|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
  [2004-01-15 15:57 UTC] vania at pandorasdream dot com
 Description: ------------ Using the example for LoadHTML the www.php.net site contains a URL with an ampersand (line 118 <a href="http://cvs.php.net/diff.php/php-src/NEWS?login=2&r1=1.1247.2.452&r2=1.1247.2.522">NEWS</a> file.). The error says it is looking for a missing ";", apparently thinking it should be an entity. When I remove the try/catch, no errors occur, but nothing gets printed. Using a different URL to a file without the & works correctly. Reproduce code: --------------- <?php try { $dom = new domdocument; @$dom->loadHTMLFile("http://www.php.net/"); $xp = new domxpath($dom); $result = $xp->query("/html/head/title"); print $result[0]->firstChild->data; } catch (exception $exc) { print $exc->getMessage()." at line ".$exc->getLine(); } ?> Expected result: ---------------- PHP: Hypertext Preprocessor Actual result: -------------- <?php try { $dom = new domdocument; @$dom->loadHTMLFile("http://www.php.net/"); $xp = new domxpath($dom); $result = $xp->query("/html/head/title"); print $result[0]->firstChild->data; } catch (exception $exc) { print $exc->getMessage()." at line ".$exc->getLine(); } ?> PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             | |||||||||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 15:00:01 2025 UTC | 
<?php $dom = new domdocument; $dom->loadHTMLFile("http://www.php.net/"); $xp = new domxpath($dom); $result = $xp->query("/html/head/title"); print $result[0]->firstChild->data; ?> //test requested without try/catch or suppression. //Emailed to rrichards@php.net per request, but since //it's not too much info, pasted here as well. Above is //code block, and below is the result. Warning: domdocument::loadHTMLFile() [function.loadHTMLFile]: htmlParseEntityRef: expecting ';' in http://www.php.net/, line: 134 in e:\PHP\projectcodewiki\www\test\loadhtmlsimple.php on line 3 Warning: domdocument::loadHTMLFile() [function.loadHTMLFile]: htmlParseEntityRef: expecting ';' in http://www.php.net/, line: 134 in e:\PHP\projectcodewiki\www\test\loadhtmlsimple.php on line 3 Warning: domdocument::loadHTMLFile() [function.loadHTMLFile]: htmlParseEntityRef: no name in http://www.php.net/, line: 228 in e:\PHP\projectcodewiki\www\test\loadhtmlsimple.php on line 3 Warning: domdocument::loadHTMLFile() [function.loadHTMLFile]: Unexpected end tag : p in http://www.php.net/, line: 349 in e:\PHP\projectcodewiki\www\test\loadhtmlsimple.php on line 3 Fatal error: Cannot use object of type domnodelist as array in e:\PHP\projectcodewiki\www\test\loadhtmlsimple.php on line 6