Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.