Re: [問題] 夾在中間的字

作者: guardlan (亞修)   2010-11-19 17:50:01
※ 引述《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&amp;area=mid&amp;item=0010481014" title="人生不設 限:我那好得不像話的生命體驗">人生不設限:我那好得不像話的生命體驗</a>
[1] => 人生不設限:我那好得不像話的生命體驗
)
另外...為什麼你要iconv big5轉utf-8?
我看他原始的網站就是用utf-8的...
你轉過之後反而會抓不到東西...
作者: frsnic (路人)   2009-01-19 18:21:00
博客x預設是big5阿 ~"~ 原來是iconv的關係

Links booklink

Contact Us: admin [ a t ] ucptt.com