作者guardlan (亞修)
看板RegExp
標題Re: [問題] 夾在中間的字
時間Fri Nov 19 17:50:01 2010
※ 引述《frsnic (路人)》之銘言:
: 附上我的原始程式好了
: $url = "http://search.books.com.tw/exep/openfind.php?key=9789861752068";
: $text = iconv("big5", "utf-8",file_get_contents($url));
: preg_match('/<a rel=\"mid_name\" href=\"[^\"]*\" \
: title=\"([^\"]*)\"[^\>]*\>/', $text, $match);
: print_r($match);
: 結果
: Array ( [0] => Array ( )
: [1] => Array ( )
: )
: 我不懂的是為什麼我抓到的都會是陣列呢 ~"~
上一篇的因為我 <a ... 忘記補上反斜線了... 要是 \<a 才對
這次我有幫你測過
$url = "
http://search.books.com.tw/exep/openfind.php?key=9789861752068";
//$text = iconv("big5", "utf-8",file_get_contents($url));
$text = file_get_contents($url);
preg_match('/\<a rel=\"mid_name\" href=\"[^\"]*\" title=\"([^\"]*)\"\>[^\<]*\<\/a\>/', $text, $match);
print_r($match);
測試可以正常抓到資料
Array
(
[0] => <a rel="mid_name" href="
http://search.books.com.tw/exep/prod_search_redir.php?key=9789861752068&area=mid&item=0010481014" title="人生不設 限:我那好得不像話的生命體驗">人生不設限:我那好得不像話的生命體驗</a>
[1] => 人生不設限:我那好得不像話的生命體驗
)
另外...為什麼你要iconv big5轉utf-8?
我看他原始的網站就是用utf-8的...
你轉過之後反而會抓不到東西...
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 111.250.168.73
1F:推 frsnic:博客x預設是big5阿 ~"~ 原來是iconv的關係 11/19 18:21