RSS

How to get innerHTML in a DIV with DOM

05 Jul

We need to get the content inside DIV container with the ID of test in get_geo_location.php.
content.php

<html>
<head></head>
<body>
<div id="test"><p>I like blogging</p></div>
</body>
</html>

Output should be :  <p>I like blogging</p>

$content="content.php";
$source=new DOMdocument();
$source->loadHTMLFile($content);
$path=new DOMXpath($source);
$dom=$path->query("*/div[@id='test']");
if (!$dom==0) {
foreach ($dom as $dom2) {

$tmp_doc = new DOMDocument();
$tmp_doc->appendChild($tmp_doc->importNode($dom2,true));
$innerHTML .= $tmp_doc->saveHTML();
echo $innerHTML;
}
}
Advertisements
 
Leave a comment

Posted by on July 5, 2012 in PHP

 

Tags: ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: