[請益] 正規表示法

看板PHP作者 (rika￾ ￾N￾ ￾ )時間18年前 (2007/05/17 21:19), 編輯推噓1(107)
留言8則, 3人參與, 最新討論串1/3 (看更多)
假如我要抓下面網頁中的藝術文化 導覽 活動 攝影...\等tag 請問用正規法要怎麼寫呢?? 我怎麼寫都錯誤@@""" <font class=mbody><a href="" rel="nofollow">http://tw.dir.yahoo.com/Art/"><b>藝術文化</b></a> </font><br> <a href="" rel="nofollow">http://tw.dir.yahoo.com/art/Guidelines/">導覽</a>,&nbsp;<a href= "" rel="nofollow">http://tw.dir.yahoo.com/art/Activities/">活動</a>,&nbsp;<a href= "" rel="nofollow">http://tw.dir.yahoo.com/art/classification/Photography/">攝影</a>, &nbsp;<a href="" rel="nofollow">http://tw.dir.yahoo.com/art/classification/music/Singers/"> 歌手歌星</a><br> <a href="" rel="nofollow">http://tw.dir.yahoo.com/art/Comments/">評論</a>,&nbsp;<a href="http: //tw.dir.yahoo.com/art/classification/Painting/">繪畫</a>,&nbsp;<a href="http: //tw.dir.yahoo.com/art/classification/design_arts/Construction/">建築</a>,&nbs p;<a href="" rel="nofollow">http://tw.dir.yahoo.com/art/classification/Traditional_Art/">傳統藝 術</a> 以下是我寫的.... <? $str = file_get_contents("http://tw.dir.yahoo.com/"); preg_match("<a href="*/s"," rel="nofollow">http://*">*</a>/s", $str, $matches); echo $matches[1]; ?> 可是這樣好像不太對@@a 有爬文了可是還是不知道怎麼寫... -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.129.161.41

05/17 21:21, , 1F
'/<a href="http:\/\/*">*<\/a>/s'
05/17 21:21, 1F

05/17 21:22, , 2F
等等 上一行不太對
05/17 21:22, 2F

05/17 21:22, , 3F
'/<a href="http:\/\/.*">(.*)<\/a>/' 這樣好像有比較對
05/17 21:22, 3F

05/17 21:23, , 4F
我其實有點忘了s選項是什麼意思了...
05/17 21:23, 4F

05/17 22:21, , 5F
那是不是每次都要加上/ /s ? 因為我不加就不能用
05/17 22:21, 5F

05/17 22:28, , 6F
你下面那個可以用耶:) 不過只跑出一個@ @
05/17 22:28, 6F

05/17 22:41, , 7F
ereg_replace( "<[^<]*>", "", $str)
05/17 22:41, 7F

05/17 22:52, , 8F
謝謝大家 可以用了:D
05/17 22:52, 8F
文章代碼(AID): #16J5POnp (PHP)
討論串 (同標題文章)
文章代碼(AID): #16J5POnp (PHP)