Hi everyone... I am trying to getElementById (like in javascript) but this time in PHP. But, I have a problem ... <?PHP //Add the content on the page $doc = new DOMDocument(); $doc->validateOnParse = true; $doc->loadHTMLFile('/home/limebl5/public_html/ms/templates/' . $templateid . '/index.php'); //echo innerHTML content of the area id (this is where I have a problem) echo $doc->getElementById('area'); ?> PHP: the html document looks like this... <div id="area">yeah this is the content that I want to show...</div>
<?php $html = file_get_contents('/home/limebl5/public_html/ms/templates/' . $templateid . 'index.php'); $dom = new DOMDocument(); @$dom->loadHTML($html); $div = $dom->getElementByID('area'); echo $div->firstChild->data; ?> PHP: Should work, I think. InnerHTML won't work because it's not actually part of the DOM, just a pseudo property added by browsers.
Try this... <?PHP //Add the content on the page $innerHTML = ''; $doc = new DOMDocument(); $doc->validateOnParse = true; $doc->loadHTMLFile('/home/limebl5/public_html/ms/templates/' . $templateid . '/index.php'); $children = $doc->childNodes; foreach ($children as $child) { $tmp_doc = new DOMDocument(); $tmp_doc->appendChild($tmp_doc->importNode($child,true)); $innerHTML .= $tmp_doc->saveHTML(); } //echo innerHTML content of the area id (this is where I have a problem) echo $innerHTML; ?> PHP:
Thank you antigravity for you're replay... I tried you're code but it returns... Catchable fatal error: Argument 1 passed to DOMNode::appendChild() must be an instance of DOMNode, boolean given in /home/limebl5/public_html/ms/view.php on line 132 Line 132 is: $tmp_doc->appendChild($tmp_doc->importNode($child,true)); My ultimate goal is to load a template, replace the ids with the users content and send it to the users computer.