Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


PHP help needed
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

PHP help needed

VictorVictor Member
edited January 2013 in Help

Hey,

I am trying to code a script to crawl specific site for specific data, but after several attempts at debugging, I still can't figure out why it's not working..the error log just says parse error, unexpected "[" and ">".

This is my code, would appreciate some pointers/help. :) Thanks.

<?php
include_once('simple_html_dom.php');

$target_url = "http://url";

$html = new simple_html_dom();

$html->load_file($target_url);
foreach($html->find('div[class=results-list]') as $list)
foreach($html->find('div[class=results-list first]') as $firstlist)

{

$firstproduct = $firstlist->find('a[h3], div[price-detail]');

echo $firstproduct.”
”; } { $product = $list->find('a[h3], div[price-detail]'); echo $product.”
”; } ?>

Thanks all.

P.S: The parser's manual, http://simplehtmldom.sourceforge.net/manual.htm

Comments

  • DeanDean Member
    edited January 2013

    $target_url is missing the second "

    Also, usually PHP will give you a line number where the problem is occuring.

  • DeanClinton is right. Everything else is technically okay, although the quotation marks you're using, ”, are not going to be recognized as valid, and cause a PHP_NOTICE to be generated.

  • @DeanClinton: That's my fault, I just deleted it by mistake when pasting here. But yea, the "[" was at line 9 and ">" at line 16.

    Line 9= foreach($html->find('div[class=results-list]') as $list)
    Line 16= echo $firstproduct.”
    ”;

    Thanks. :)

  • klikliklikli Member
    edited January 2013

    It's the problem I guess.

    ” is different from " and can't be parsed by PHP

    (Sorry for putting them in a h3, I am just attempting to contrast the difference)

  • DeanDean Member
    edited January 2013

    @klikli Yeah, I was just thinking that.

    Replace

    echo $firstproduct.”
    ”;

    with

    echo $firstproduct."
    ";

    then replace

    echo $product.”
    ”;

    with

    echo $product."
    ";
  • You might want to use PHP_EOL as a new line.
    It acts like \n but PHP_EOL automagically detects the OS and gives the correct EOL.

  • Alright, no more errors..but it's not showing any data as well. :(

  • What kind of object should find() return?

  • I have actually used the exactly same HTML parser, should you feel free you are welcomed to message me the whole script and we could work out a solution.

Sign In or Register to comment.