PDA

View Full Version : Giúp mình sửa lỗi trong đoạn ví dụ ngắn về PHP DOM



vuongkiet0605
28-01-2011, 03:30
Mình có một đoạn code ví dụ ngắn như sau


1.<?php
2.$html = file_get_contents("http://dantri.com.vn/");
3.$dom = new domDocument;
4.$dom->loadHTML($html);
5.$content = $dom->getElementsByTagname('title');
6.foreach($content as $item){
7. echo $item->nodeValue;
8.}
9.?>


Mặc dù vẫn in ra được nội dung trong trong cặp thẻ title nhưng có xuất hiện thông báo một số lỗi tại dòng 4 như sau:

Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: Unexpected end tag : a in Entity, line: 90 in C:\xampp\htdocs\php\index.php on line 4

Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: htmlParseEntityRef: expecting ';' in Entity, line: 117 in C:\xampp\htdocs\php\index.php on line 4

Đại loại là vậy, bạn nào biết sủa giùm mình với, mình không hiểu sao lại bị lỗi này.

interboy
28-01-2011, 23:24
Chạy đoạn này coi:
1.<?php
2.$html = file_get_contents("http://dantri.com.vn/");
3.$dom = new domDocument;
4.$dom->loadHTML($html);
5.$content = $dom->getElementsByTagname('title');
6.foreach($content as $item){
7. echo $item;
8.}
9.?>

Ko đc pm truonghanu nhé