即時通訊使用dom文件getElementsByTagName檢索網站標題。php dom文件刪除特殊字符
這裏是我的代碼:
$doc = new DOMDocument();
@$doc->loadHTML($strData);
$doc->encoding = 'utf-8';
$doc->saveHTML();
$titleNode = $doc->getElementsByTagName("title");
它工作正常,但當有特殊字符在標題中,檢索數據是不準確的。即時獲得「Some More Google Plus Invite Workarounds #wrapper { background:url(/) no-repeat 50% 0; } body { background:#CFD8E2; }
」而不是。
我做了以下替換特殊字符,但它沒有工作:
// Replace all special characters into space
$specialChars = array('~','`','!','@','#','$','%','^','&','*','(',')','-','_','=','+','|','\\',']','[','}','{','"','\'',':',';','/','?','.',',','>','<');
foreach ($specialChars as $a) {
$titleNode = str_replace($a, ' ', $titleNode);
}
即時得到空標題來代替。該<title>
值是財產以後這樣的:
<title>Some More Google Plus Invite Workarounds < Communication, Social Networking < PC World India News < PC World.in</title>
所以我應該怎麼做
嗯,它是否讀取「小於」(<)作爲html標籤的開始? –
喲,它是..閱讀後,它跳轉到閱讀CSS樣式。 – nuttynibbles
使用解析器+1! –