4
I’m trying this way
libxml_use_internal_errors(true);
//pegar o conteudo de um pagina web
$doc = new DomDocument();
$doc->loadHTMLFile('http://www.astralsaudeambiental.com.br/');
$div = $doc->getElementById('sidebar');
$string_div = '';
foreach($div->childNodes as $node) {
$string_div .= $doc->saveHTML($node);
}
if(!$div)
{
die("Element not found");
}
//alterar o conteudo de um arquivo HTML em determinada div
$content_doc = new DomDocument();
$content_doc -> loadHTML('<html><head><title>titulo</title></head><body><div style="width:200px;height:200px;background:#000000;"></div><div id="sidebar"></div></body> </html>');
$content_doc -> getElementById('sidebar')->nodeValue = $string_div;
$content_doc_div = $content_doc -> getElementById('sidebar');
$content_doc_div_string = '';
foreach($content_doc_div->childNodes as $node) {
$content_doc_div_string .= $content_doc->saveHTML($node);
}
echo $content_doc -> saveHTML();
But the content is inserted into the HTML file so that it appears as text
<div class="unidades box clear">
<h2>Encontre a unidade mais próxima de você!</h2>
<div>
<p>cConteudo.<br>
Use o campo abaixo para buscar a<br>
unidade mais próxima da sua cidade:</p>
<p></p>
You want to generate structured Html from another Html?
– Marcelo Aymone
Try using html_entity_decode() within saveHTML().
– Onaiggac
Yes, I want to insert the contents of a div of a site into another html file, but this way the tags are treated as text
– user5020
didn’t work out :/
– user5020
You can try creating another Document for this piece of HTML and then import it into your DIV, like this: http://stackoverflow.com/questions/4400980/how-to-insert-html-to-php-domnode
– Anderson Danilo