Board logo

標題: [操作疑難] PHP DOM Parser失敗 [打印本頁]

作者: whitelove1    時間: 2017-3-6 13:44     標題: PHP DOM Parser失敗

<? php
$dom = new DOMDocument('1.0','UTF-8');
$dom->loadHTML('<html><body><div class="hkepc">first</div><div class="hkepc">second</div></body></html>');        
$node = $dom->getElementsByClassName('hkepc')->item(0);              
$innerHTML = '';
foreach ($node->childNodes as $childNode){
$innerHTML .= $childNode->ownerDocument->saveHTML($childNode);
}
echo htmlspecialchars($innerHTML);
?>

請問各位師兄我段code有什麼問題? 為什麼輸出不到「first」,請各位幫幫手。
作者: max918    時間: 2017-3-6 14:45

http://php.net/manual/en/class.domdocument.php

無一個method叫 getElementsByClassName
作者: ykmran    時間: 2017-3-7 00:42

用php parse xml真係會好痛苦
公司網主要係php,但拆網部份一定唔係php
作者: 清仔    時間: 2017-3-8 12:34

http://simplehtmldom.sourceforge.net/ 會簡單d…
因為係jQuery style





歡迎光臨 電腦領域 HKEPC Hardware (https://www.hkepc.com/forum/) Powered by Discuz! 7.2