Jump to content

Searching HTML results of file_get_contents()


pitbullent

Recommended Posts

Hi!

  I'm SO CONFUSED. OK all I want to do is use PHP to access a specific website and display only the content of a specific DIV on that website.  The class of the div is "content_box".

 

<div class="content_box">

 

My thoughts lead me to think that I can use

 

$results = file_get_contents('website');

 

to put all of the HTML into a variable and then use one of the preg functions to extract the div and display it.

 

preg_match('<div class=\"content_box\"> *allow anything including nested divs* </div>', $results, $div);
print $div;

 

This is where my ideas fall apart. I have absolutely no idea on how to get started on the regex for a specific div much less allowing for nested divs.

 

Is this the wrong approach altogether? Thank you so much in advance for any ideas or code you can supply!

Link to comment
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.