Re: [問題] 夾在中間的字
看板RegExp (正規表示式 Regular Expression)作者guardlan (亞修)時間14年前 (2010/11/19 14:29)推噓0(0推 0噓 0→)留言0則, 0人參與討論串2/4 (看更多)
※ 引述《frsnic (路人)》之銘言:
: <a rel="mid_name" href="http://xxxxx" title="書名">
: 請問這要怎麼抓出書名 ~"~ 改了一個早上還是弄不出來
: 我是用php的preg_match
=============================================
程式:
=============================================
$string = '<a rel="mid_name" href="http://xxxxx" title="書名">';
preg_match('/<a rel=\"[^\"]*\" href=\"[^\"]*\" title=\"([^\"]*)\"[^\>]*\>/', $string, $matches);
print_r($matches);
=============================================
結果:
=============================================
Array
(
[0] => <a rel="mid_name" href="http://xxxxx" title="書名">
[1] => 書名
)
如果你要解析的文章有很多 <a rel="mid_name" href="http://xxxxx" title="書名"> 這種東西的話
請用 preg_match_all 才能抓到很多個
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.36.168.98
討論串 (同標題文章)
RegExp 近期熱門文章
PTT數位生活區 即時熱門文章