-1

I Build A Basic Web Crawler To Pull Information From A Website . For it I create simple_html_dom.php.

Now my code is like

<?php
    include_once('simple_html_dom.php');
    $target_url = "http://www.example.com/";
    $html = new simple_html_dom();
    $html->load_file($target_url);
    foreach($html->find('a') as $link) {
        echo $link->href."<br />";
    }
?>

I get the error

Parse error: syntax error, unexpected ':' in C:\xampp\htdocs\test\test.php on line 3

what is the problem plz help

Nate
  • 18,752
  • 8
  • 48
  • 54
user3065043
  • 57
  • 2
  • 9

4 Answers4

0

Your double quotes and single quotes are weird. I suspect a keyboard problem..

The normal single quote that PHP accepts is ', yours is

The normal double quote that PHP accepts is ", yours is

Your fixed code would be:

<?php
include_once('simple_html_dom.php');
$target_url = "http://www.xyz.com/";
$html = new simple_html_dom();
$html->load_file($target_url);
foreach($html->find('a') as $link){
echo $link->href."<br />";
}

?>

Ali
  • 3,479
  • 4
  • 16
  • 31
0

I think you're just using wrong quotes for your string.

Wrong: “string“

Right: "string"

Or: 'string'

Please check your keyboard settings

Tim S.
  • 13,597
  • 7
  • 46
  • 72
0

It seems you have copy paste this code . Wrong single and double quotes in your block of code. change to " and to ' . Your correct block of code are :-

<?php
    include_once('simple_html_dom.php');
    $target_url = "http://www.example.com/";
    $html = new simple_html_dom();
    $html->load_file($target_url);
    foreach($html->find('a') as $link) {
        echo $link->href."<br />";
    }
?>
D. Schreier
  • 1,700
  • 1
  • 22
  • 34
Roopendra
  • 7,674
  • 16
  • 65
  • 92
  • how to pull all the website .this code only pull info of the current page. – user3065043 Dec 04 '13 at 09:20
  • Here is the reference link it will be helpful to you. http://davidwalsh.name/curl-download and http://stackoverflow.com/questions/4365011/how-to-get-content-from-external-web-page-by-php. these exactly do the same thing. Your code only extract link from that web page.. – Roopendra Dec 04 '13 at 09:24
0

from what you have pasted, your have not used a proper double quote to encapsulate your string $target_url = "http://www.xyz.com/"; use "

DevZer0
  • 13,433
  • 7
  • 27
  • 51