Reputation: 2077
I have a page being generated by from an rss feed, but it is being generated with additional html
, head
, and body
tags. I would like to get only one div
and it's contents from that page and load it into my page. I figured I would need to use curl
to load from the page and I found many examples of loading the entire page, but how can I load only the specific div I am looking for?
Upvotes: 0
Views: 2689
Reputation: 41958
First of all, no reason to use curl for a simple page download, just use:
$html = file_get_contents('http://www.stackoverflow.com');
After that you have 2 options:
strpos
and substr
to find the specific part of the code you care about.Purists usually hate on option 2, because it is inherently inferior to the first on a lot of aspects. It is however also much less work to code and for bad source code most probably more reliable. Which option you want to use is up to you - for a simple one-off case I'd definitely go for the simple approach and use a regexp if you know them, or strpos
if you don't.
Upvotes: 2