Simple HTML DOM parsing doesn't work
I am trying to learn HTML DOM parsing on my localhost. But I collapsed right in the beginning.
1) I created a new project
2) I downloaded the files from simplehtmldom.sourceforge.net
3) I have put this code in my HTML project
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<?php
// put your code here
$html = file_get_html('http://www.google.com/');
?>
</body>
</html>
4) I am getting this error when I run the script:
Fatal error: Failed Error: Call to undefined function file_get_html () in C: \ xampp \ htdocs \ PhpProject1 \ index.php: 15 Stack trace: # 0 {main} selected in C: \ xampp \ htdocs \ PhpProject1 \ index.php on line 15
Am I not understanding something?
source to share
I think the PHP DOM Parser Library no longer supports the latest PHP version , so you need to use cURL for this. This will help you.
<?php
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "http://www.google.co.in");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);
curl_close($curl);
print $result;
?>
Try it..!
source to share
file_get_html
does not belong php
.
To use it, you need to download and enable PHP Simple HTML DOM Parser .
Then you can use it like this:
include_once('simple_html_dom.php');
$html = file_get_html('http://www.google.co.in');
source to share
You need to include the PHP DOM parser library file in your HTML using the PHP include function.
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<?php
include_once('domparser.php');// use your file location
// put your code here
$html = file_get_html('http://www.google.com/');
?>
</body>
</html>
source to share