看板 PHP 關於我們 聯絡資訊
各位版友晚安 有問題想請教各位 假設 $html 是網頁的 html 我要抓在這些class底下 <a> 裡面 href的連結 (會有多筆) <div class="a1_class"> <h3 class="a2_class a3_class"> <a href="http://xxxxxxxxxxxxxxxxxx">文字文字文字</a> <h3> $preg = '/<div class="a1_class">.*?<h3 class="a2_class a3_class">.*? <a .*? href="(.*?)">/s</a>.*?</h3>'; preg_match_all($preg,$html,$match); 可是我 輸出 $match 卻沒有內容 想請教一下 我是否哪邊有寫錯 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 119.77.199.20 ※ 文章網址: https://www.ptt.cc/bbs/PHP/M.1524501108.A.43A.html
MOONRAKER: 用 / 開頭 最後沒有 / 中間卻有好幾個沒escape 04/24 10:36
MOONRAKER: 這樣沒有錯誤訊息 不可思議 04/24 10:38
MOONRAKER: https://www.regextester.com/ 這個站不錯 04/24 10:40
MOONRAKER: 要用regex先自己在上面玩一玩 04/24 10:40
MOONRAKER: 還有抓HTML內容 simplehtmldom卡實在 04/24 10:41
liisi: 我剛用這網站 先用 <div class=\"a1_class\"> 有match到 04/24 11:22
liisi: 但是如果之後繼續加上 .*?<h3 就沒有任何match了 04/24 11:23
liisi: 是換行問題嗎 囧rz 04/24 11:24
MOONRAKER: 換行很煩 就這個而言改用 \s* 就可以繼續match 04/24 12:09
MOONRAKER: 不過通常看到多行就會想別的方法了 04/24 12:10