miniramen Posted May 31, 2010 Share Posted May 31, 2010 Hello, I'm new to dom documents and xpath so I was trying some codes to get myself more familiar to it, but this generated an error...can someone tell me why? <?php $url = "http://www.village.consort.ab.ca/business-directory/"; $data = file_get_contents($url); $dom = new DomDocument(); @$dom -> loadHTMLFile($data); $xpath = new DOMXPath($dom); $divtags = $xpath->getElementsByTagName("class"); Quote Link to comment https://forums.phpfreaks.com/topic/203443-simple-dom-question/ Share on other sites More sharing options...
ohdang888 Posted May 31, 2010 Share Posted May 31, 2010 post the error Quote Link to comment https://forums.phpfreaks.com/topic/203443-simple-dom-question/#findComment-1065806 Share on other sites More sharing options...
ohdang888 Posted May 31, 2010 Share Posted May 31, 2010 Plus, i've never heard of a <class> tag...which is what you're calling in $xpath->getElementsByTagName("class"); Quote Link to comment https://forums.phpfreaks.com/topic/203443-simple-dom-question/#findComment-1065808 Share on other sites More sharing options...
premiso Posted May 31, 2010 Share Posted May 31, 2010 That and unsupress the error message when loading html data. That will probably give you a better understanding of the real error: @$dom -> loadHTMLFile($data); //TO: $dom -> loadHTMLFile($data); And see what feedback it gives you. Quote Link to comment https://forums.phpfreaks.com/topic/203443-simple-dom-question/#findComment-1065809 Share on other sites More sharing options...
miniramen Posted May 31, 2010 Author Share Posted May 31, 2010 oh sorry about the class tag that doesn't exist, I replaced it with div tag. Now as for the error msg without that "@" inside the code... Warning: DOMDocument::loadHTMLFile() [domdocument.loadhtmlfile]: I/O warning : failed to load external entity " <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en-ca"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Business Directory » index</title> <link href="/favicon.ico" type="image/x-icon" rel="icon" /><link href="/favicon.ico" type="image/x-icon" rel="shortcut icon" /> <meta name="keywords" content=""/> <meta name="description" content=""/> <link rel="stylesheet" type="text/css" href="/css/blueprint/screen.css" media="screen, projection" / in C:\xampp\htdocs\xampp\new.php on line 8 Fatal error: Call to undefined method DOMXPath::getElementsByTagName() in C:\xampp\htdocs\xampp\new.php on line 11 The code right now: <?php $url = "http://www.village.consort.ab.ca/business-directory/"; $data = file_get_contents($url); $dom = new DomDocument(); $dom -> loadHTMLFile($data); $xpath = new DOMXPath($dom); $divtags = $xpath->getElementsByTagName("div"); Quote Link to comment https://forums.phpfreaks.com/topic/203443-simple-dom-question/#findComment-1065811 Share on other sites More sharing options...
ignace Posted May 31, 2010 Share Posted May 31, 2010 $dom -> loadHTMLFile($data); It's $dom->loadHtml($data); Use File() when you are actually loading a file. To suppress the invalid errors use libxml_use_internal_errors(true); Quote Link to comment https://forums.phpfreaks.com/topic/203443-simple-dom-question/#findComment-1065871 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.