Jump to content

Simple Dom question


miniramen

Recommended Posts

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");

 

Link to comment
https://forums.phpfreaks.com/topic/203443-simple-dom-question/
Share on other sites

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");

Link to comment
https://forums.phpfreaks.com/topic/203443-simple-dom-question/#findComment-1065811
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.