Wednesday, July 4, 2012

How to get innerHTML in a DIV with DOM

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

[sourcecode language="html"]
<html>
<head></head>
<body>
<div id="test"><p>I like blogging</p></div>
</body>
</html>
[/sourcecode]

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

[sourcecode language="php"]
$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;
}
}
[/sourcecode]

No comments:

Post a Comment

How to enable CORS in Laravel 5

https://www.youtube.com/watch?v=PozYTvmgcVE 1. Add middleware php artisan make:middleware Cors return $next($request) ->header('Acces...