我無法在PHP中使用正則表達式工作。它應該得到網頁上的標籤之間的字符串,但我所得到的回報是當我試圖回顯它時,數組字。無法使正則表達式在PHP中工作。只輸出單詞陣列
這是我正在使用正則表達式的文本。它是以字符串形式下載的網頁的一部分。
<title>
HTC Desire S
</title>
這是我用於正則表達式的代碼。
while(!feof($list_of_phones))
{
$phone = fgets($list_of_phones);
$info = file_get_contents($phone);
preg_match_all("/\/<title>(.*)<\/title>/", $info, $title, PREG_OFFSET_CAPTURE);
echo $title[0];
}
試試'preg_match'而不是'preg_match_all'。 – hakre
它看起來像你試圖用正則表達式解析HTML。看到這個問題,爲什麼這是一個壞主意:http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags –
你知道有easyer方式獲得通過使用類似[DOMDocument](http://lv.php.net/manual/en/class.domdocument.php)的html/xml文檔的內容? –