http://www.webdevout.net/browser-support
Lưu trữ của chuyên mục 'dom'
Hỗ trợ chuẩn web trên các trình duyệt
Được đăng Tháng Mười Hai 28, 2007 browser , css xhtml , dom , firefox , html , ie , standard Leave a CommentUse DOM to transform HTML table to PHP’s array
Được đăng Tháng Mười Hai 20, 2007 crawling , data-processing , dom , extracting , html , mining , php , scraping Leave a CommentPHP5’s DomDocument
$tableArray = array();
$dom = new DomDocument();
$dom->preserveWhiteSpace = false;
$dom->loadHTML($xmlstr);
// return DOMNodeList
$rows = $dom->getElementsByTagName('tr');
// loop through each row
// to work with DOMNode (nodeName, nodeType, parentNode, nodeValue, getAttribute
for ($rowIndex = 0, $length = $rows->length; $rowIndex < $length; $rowIndex++) {
// DOMElement
$currentRow = $rows->item($rowIndex);
// the same to while($currentRow->hasChildNodes())
// or foreach ($rows->item($rowIndex)->childNodes as $child) {
if (null !== $currentRow && $currentRow->hasChildNodes()) {
$cells = $currentRow->childNodes;
for ($cellIndex = 0, $length = $cells->length; $cellIndex < $length; $cellIndex++) {
$tableArray[$rowIndex][$cellIndex] = $cells->item($cellIndex)->nodeValue;
}
}
}
Đây là một cách dùng DOM để loop qua một table đơn giản
Phản hồi gần đây