0

I've tried to grab all the comments from a website (The text between <!-- and -->), but without luck.

Here is my current code:

include('simple_html_dom.php');
$html = file_get_html('THE URL');
foreach($html->find('comment') as $element)
    echo $element->plaintext;

Anyone have any ideas how to grab the comments, at the moment it's only giving me a blank page

4
  • 2
    Did you tried to print $html's value before foreach to make sure that it is loaded successfully? Commented Mar 20, 2013 at 20:20
  • Yes, then I get a big array when i print_r the output Commented Mar 20, 2013 at 20:28
  • It seems it works fine, but as you are doing echo and it outputs html comment, browser doesn't show it. Try to do var_dump($element->plaintext); to make sure that there is a value. Commented Mar 20, 2013 at 21:55
  • Don't get any output either with var_dum Commented Mar 21, 2013 at 9:08

1 Answer 1

1

I know regex is not supposed to parse HTML, but <!--(.*?)--> you can use a similar regex to find and fetch the comments...

Sign up to request clarification or add additional context in comments.

1 Comment

Yes comments are easily parsable with regex

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.