找優仕美清潔公司 大掃除免煩惱!清潔打蠟、消毒殺菌 | 加入客源網 每天多接2個客戶,做生意就是這麼簡單 |
preg_match_all() 取出網頁資料 |
房東:台灣人 發表時間:2007-05-11 |
// 下載網頁 $handle = fopen("http://www.30p.com.tw/House/House_Info.aspx?house_no=1041994", "r"); $contents = fread($handle, 10000 ); fclose($handle); // 取出資料 $result = array(); preg_match_all("/([^<]+)<\/span>/", $contents, $result, PREG_SET_ORDER); foreach ( $result as $key => $value ) { $span_id = $result[ $key ][1]; $span_value = $result[ $key ][2]; switch ( $span_id ) { case "lblContactName": $lblContactName = $span_value; break; case "lblContactMobile": $lblContactMobile = $span_value; break; case "lblContactPhone1": $lblContactPhone1 = $span_value; break; case "lblContactPhone2": $lblContactPhone2 = $span_value; break; case "lblContactEmail": $lblContactEmail = $span_value; break; } } // 顯示資料 print "姓名: $lblContactName 手機: $lblContactMobile 聯絡電話(日): $lblContactPhone1 聯絡電話(夜): $lblContactPhone2 email $lblContactEmail"; ?> |
|
廣利不動產-新板特區指名度最高、值得您信賴的好房仲 您的托付,廣利用心為您服務 廣利不動產-板橋在地生根最實在--新板特區指名度最高、值得您信賴的好房仲 完整房訊,房屋、店面熱門精選物件,廣利不動產 優質仲介,房屋租賃、買賣資訊透明,交易真安心! |
1 樓住戶:仙人 發表時間:2007-05-13 |
ob_start (); readfile ("http://www.168house.com/showpage.php?number=94567"); $data = ob_get_contents (); ob_end_clean (); preg_match_all ('/\s+ | |||
(.*)<\/font><\/td>\n\s+ | (.*)<\/font><\/td>\n\s+ | (.*)<\/font><\/td>\n\s+ | (.*)<\/font><\/td>\n\s+<\/tr>/i', $data, $matchse); print_r (trim (preg_replace ("/ /U", "", strip_tags ($matchse[0][0])))); |
2 樓住戶:阿保 發表時間:2007-05-14 |
//----- 定義要擷取的網頁地址 $url = "http://web-address"; //----- 讀取網頁源始碼 $fp = file_get_contents($url); //----- 擷取 title 資訊 preg_match("/ $title = $match[1]; //----- 擷取 Description 及 Keywords $metatag = get_meta_tags($url); $description = $metatag["description"]; $keywords = $metatag["keywords"]; //----- 印出結果 echo "URL: $url\n"; echo "Title: $title\n"; echo "Description: $description\n"; echo "Keywords: $keywords\n"; ?> |
3 樓住戶:達人 發表時間:2007-05-16 |
ob_start (); readfile ("http://www.30p.com.tw/House/House_Info.aspx?house_no=1041994"); $data = ob_get_contents (); ob_end_clean (); $data=strip_tags($data); $data1=explode(" ",$data); $i=1; foreach($data1 as $value) { echo "$i {$value} "; $i++; } ?> |
4 樓住戶:老貓 發表時間:2007-08-27 |
ob_start (); readfile ("http://www.591.com.tw/rent-detail-6166.html"); $data = ob_get_contents (); $want = array("聯 絡 人","E- mail","行動電話","固定電話"); $data = ob_get_contents (); ob_end_clean (); $body=ereg_replace( "[\"']?", "", $data); $body=str_replace("5 BR","5",$body); preg_match_all ('/(.*)<\/span><\/td>/isU', $body, $matches); $total=count($matches[1]); for($i=0;$i<$total;$i++){ $style = $matches[1][$i]; if ($style == 10 || $style == 7 ) { $style2 = $matches[1][$i+1]; if ($style2 == 5 ) { $key = strip_tags($matches[2][$i]); $value = strip_tags($matches[2][$i+1]); if (in_array($key, $want) ) printf("%s:%s\n",$key,$value); $i++; } } } ?> |
5 樓住戶:晴晴 發表時間:2007-08-29 |
$data = file_get_contents ("http://www.591.com.tw/rent-detail-7432.html"); $pattern = '/([^<]*)<\/span>/isU'; $want = array("聯絡人","E-mail","行動電話","固定電話"); preg_match_all($pattern,$data,$matched); foreach($matched[2] as $key=>$value){ $matched[2][$key] = preg_replace('/\s/','',$matched[2][$key]); if(in_array($matched[2][$key],$want)){ $result[$matched[2][$key]] = $matched[2][$key+1]; } } $table = 'info'; $query = sprintf("INSERT INTO %s (`聯絡人`,`E-mail`,`行動電話`,`固定電話`) VALUES ('%s','%s','%s','%s')", $table, $result['聯絡人'], $result['E-mail'], $result['行動電話'], $result['固定電話'] ); echo $query; if(mysql_query($query)){ echo " 完成}else{echo " 資料庫錯誤 ";}//有時候正規會出問題!不能用的時候請檢查正規表示式 //如果無法寫入資料庫直接檢查sql語法即可 |
6 樓住戶:鴨子 發表時間:2008-03-15 |
$txt = iconv("big5", "utf-8",file_get_contents("http://www.520house.com.tw/index-inquiry1-txt.asp?Key=35053&page=")); $txt = str_replace("\r\n","",$txt); $txt = str_replace("<","",$txt); $txt = str_replace(">","",$txt); $txt = str_replace("\"","",$txt); $txt = str_replace(" ","",$txt); $txt = trim($txt); $re = array ("(地址:)/div/tdtdcolspan=3(.*?)/td","(建物:)/div/tdtdwidth=52%(.*?)/td","(用途:)/div/tdtdwidth=25%(.*?)/td","(所在樓層/總樓層)/div/tdtdcolspan=(.*?)/td" ,"(總價:)/div/tdtdcolspan=3(.*?)/td","(管理員:)/div/tdtd有/td","(管理費:)/div/tdtd(.*?)/td","(坪數:)/div/tdtd(.*?)/td","(電梯:)/div/tdtd(.*?)/td","(房屋格局:)/div/tdtd(.*?)/td","(屋齡:)/div/tdtd(.*?)/td","(家具:)/div/tdtdcolspan=3(.*?)/td","(詳細說明:)/div/tdtdcolspan=3(.*?)/td","(聯絡人:)/div/tdtd(.*?)/td","(身分:)/div/tdtd(.*?)/td","(市話:)/div/tdtd(.*?)/td","(手機:)/div/tdtd(.*?)/td","(電子信箱:)/div/tdtdcolspan=3(.*?)/td"); $header = array(); $content = array(); foreach($re as $k => $v){ preg_match_all("|$re[$k]|i",$txt,$tmp); array_push($header,$tmp[1][0]); array_push($content,$tmp[2][0]); } foreach($header as $k=>$v){ echo $v.str_replace("br"," ",$content[$k])." "; } 幫你寫一個妳測試看看如果你的頁面本身是BIG5請將下面 $txt = iconv("big5", "utf-8",file_get_contents("http://www.520house.com.tw/index-inquiry1-txt.asp?Key=35053&page=")); 改成 $txt = file_get_contents("http://www.520house.com.tw/index-inquiry1-txt.asp?Key=35053&page="); |
姓名: | |||
佈告內容: | |||
其他選項: | |||
|