views:

192

answers:

2

Howdy,

I have a url I want to grab. I only want a short piece of content from it. The content in question is in a div that has a ID of sample.

<div id="sample">
   Content
</div>

I can grab the file like so:

$url= file_get_contents('http://www.example.com/');

But how do I select just that sample div.

Any ideas?

+1  A: 

I would recommend something like Simple HTML DOM, although if you are very sure of the format, you may wish to look at using regex to extract the data you want.

Yacoby
Thanks - Perfect as Andrew mentions too!
Keith Donegan
+1  A: 

I'd recommend using the PHP Simple HTML DOM Parser.

Then you can do:

$html = file_get_html('http://www.example.com/');
$html->find('div[#sample]', 0);
Andy
Thank you very much!
Keith Donegan