html in html?!
code is
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?php
$doc = new DOMDocument();
$doc->loadHTML(file_get_contents($path));
$domAttribute = $doc->createAttribute("id");
$domAttribute->value = "photo";
//$doc->loadHTML(file_get_contents($path));
foreach ($doc->getElementsByTagName('img') as $image){
$image->appendChild($domAttribute);
// print "<!--" . $image->nodeName . "-->";
}
print "<div id=\"" . basename($path, ".html") . "\" class=\"content text\">" . $doc->saveHTML() . "</div>";
?>
$doc = new DOMDocument();
$doc->loadHTML(file_get_contents($path));
$domAttribute = $doc->createAttribute("id");
$domAttribute->value = "photo";
//$doc->loadHTML(file_get_contents($path));
foreach ($doc->getElementsByTagName('img') as $image){
$image->appendChild($domAttribute);
// print "<!--" . $image->nodeName . "-->";
}
print "<div id=\"" . basename($path, ".html") . "\" class=\"content text\">" . $doc->saveHTML() . "</div>";
?>
Gewijzigd op 27/04/2012 12:11:00 door Reshad F
Sla je image op als var en doe dan saveHtml($image).
Code (php)
1
2
3
4
2
3
4
<?php
$doc->removeChild($doc->firstChild);
$doc->replaceChild($doc->firstChild->firstChild->firstChild, $doc->firstChild);
?>
$doc->removeChild($doc->firstChild);
$doc->replaceChild($doc->firstChild->firstChild->firstChild, $doc->firstChild);
?>
dan krijg ik alleen images en geen text meer
maar verander ik regel 2 in
dan behoud ik de <body> tag
Toevoeging op 27/04/2012 13:08:26:
edit: heb het heel makkelijk opgelost heb de docs weggehaald helemaal en alleen dit gedaan (str_replace)
<php
print "<div id=\"" . basename($path, ".html") . "\" class=\"content text\">" . str_replace("<img", "<img id=\"photo\"", file_get_contents($path)) . "</div>";
?>
Heb je überhaupt gelezen wat ik schreef?