[請益] 有關preg_match的問題

看板PHP作者 ( )時間16年前 (2009/07/25 13:05), 編輯推噓2(201)
留言3則, 3人參與, 最新討論串1/1
想要擷取一段網頁原始碼的內容 目標是<item>和</item>間的字串 原始檔如下: http://0rz.tw/7tX6U 程式碼: $url = "http://0rz.tw/7tX6U"; $str = file_get_contents($url); preg_match("/<item>\s*(.*)\s*<\/item>/Uis", $str,$match); echo $match[0]; 跑出來的結果是將所有的tag和一些內容去除掉 但我想要的是保留所有的tag及內容 我試過DOM結果也是一樣 請問要怎麼寫才能得到我要的結果呢? 謝謝各位版友! -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 123.194.151.6 ※ 編輯: justlonelygo 來自: 123.194.151.6 (07/25 13:10)

07/25 16:37, , 1F
$match[0]是原字串 $match[1]才是第一個()裡的東西
07/25 16:37, 1F

07/25 16:57, , 2F
不論是$match[0]或$match[1] 結果都不是我要的
07/25 16:57, 2F

07/25 17:15, , 3F
preg_match_all ?
07/25 17:15, 3F
文章代碼(AID): #1AQfAac4 (PHP)
文章代碼(AID): #1AQfAac4 (PHP)