Example HTML...
<html>
<head></head>
<body>
<table>
<tr>
<td class="rsheader"><b>Header Content</b></td>
</tr>
<tr>
<td class="rstext">Some text (Most likely will contain lots of HTML</td>
</tr>
</table>
</body>
</html>
I need to convert a page of HTML into a templated version of that HTML page. The HTML page is made up of several boxes, each with a header (refered to in the above code as "rsheader") and some text (refered to in the above code as "rstext").
I'm trying to write a PHP script to retrieve the HTML page maybe using file_get_contents and then to extract whatever content is within the rsheader and rstext divs. Basically I don't know how to! I've tried experimenting with DOM but I don't know it too well and although I did manage to extract the text, it ignored any HTML.
My PHP...
<?php
$html = '<html>
<head></head>
<body>
<table>
<tr>
<td class="rsheader"><b>Header Content</b></td>
</tr>
<tr>
<td class="rstext">Some text (Most likely will contain lots of HTML</td>
</tr>
</table>
</body>
</html>';
$dom = new DomDocument();
$dom->loadHtml($html);
$xpath = new DomXpath($dom);
$div = $xpath->query('//*[@class="rsheader"]')->item(0);
echo $div->textContent;
?>
If I do a print_r($div) I see this...
DOMElement Object
(
[tagName] => td
[schemaTypeInfo] =>
[nodeName] => td
[nodeValue] => Header Content
[nodeType] => 1
[parentNode] => (object value omitted)
[childNodes] => (object value omitted)
[firstChild] => (object value omitted)
[lastChild] => (object value omitted)
[previousSibling] =>
[nextSibling] => (object value omitted)
[attributes] => (object value omitted)
[ownerDocument] => (object value omitted)
[namespaceURI] =>
[prefix] =>
[localName] => td
[baseURI] =>
[textContent] => Header Content
)
As you can see there are no HTML tags within the textContent node which leaves me to believe I'm going about it the wrong way :(
Really hoping someone might be able to give me some help with this...
Thanks in advance
Paul