
Untitled
By: a guest on
Jun 27th, 2012 | syntax:
None | size: 0.62 KB | hits: 7 | expires: Never
PHP DOM echoing the HTML inside a DOMNode? [closed]
<tr>
<td>first <span>hello</span> td</td>
<td>second td</td>
</tr>
//etc
$tr = $dom->getElementsByTagName('tr');
echo $tr->item(0)->textContent;
// textContent prints only text without html :(
$str = '<tr>
<td>first <span>hello</span> td</td>
<td>second td</td>
</tr>';
$dom = new DOMDocument();
$dom->loadHTML($str);
$tr = $dom->getElementsByTagName('tr');
echo $dom->saveXML($tr->item(0));
<tr><td>first <span>hello</span> td</td>
<td>second td</td>
</tr>
foreach ($tr->item(0)->childNodes as $child) {
echo $dom->saveXML($child);
}