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

看板RegExp (正規表示式 Regular Expression)作者 (亞修)時間14年前 (2010/11/19 17:50), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串4/4 (看更多)
※ 引述《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的... 你轉過之後反而會抓不到東西... -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 111.250.168.73

11/19 18:21, , 1F
博客x預設是big5阿 ~"~ 原來是iconv的關係
11/19 18:21, 1F
文章代碼(AID): #1CvaXBWE (RegExp)
討論串 (同標題文章)
文章代碼(AID): #1CvaXBWE (RegExp)