tags:

views:

56

answers:

2

suppose i echo out

$url = "http://www.mydomain.com";
echo file_get_content($url);

and http://www.mydomain.com has a div i.e

<title>sitename</title>
</head><body>
Lorem Ipsum.......
<div id="divname">and here is div content</div>
Copyright bla bla bla

no i want to only fetch content between div with id="divname" how can i do that

+2  A: 
$url = "http://www.mydomain.com";
$html =  new SimpleXmlElement($url, null, true);

$content = $html->xpath("//div[@id='divname']");

Of course you could still use file_get_contents or curl if you want to introduce error checking on the fetch of the document.

prodigitalson
A: 

With Simple HTML DOM Parser

$url = "http://www.mydomain.com";
$html = file_get_html($url);
$ret = $html->find('div[id=divname]');
isola009
Raw PHP doesn't have a file_get_html() function
stillstanding
You should add that you’re using [Simple HTML DOM Parser](http://simplehtmldom.sourceforge.net/).
Gumbo
Yes, is necessary use SImple HTML DOM Parser.
isola009
@isola009: Well, then add that to your answer.
Gumbo