Note that there are some explanatory texts on larger screens.

plurals
  1. POExtract all content (including HTML) from a div class using PHP
    primarykey
    data
    text
    <p>Example HTML...</p> <pre><code>&lt;html&gt; &lt;head&gt;&lt;/head&gt; &lt;body&gt; &lt;table&gt; &lt;tr&gt; &lt;td class="rsheader"&gt;&lt;b&gt;Header Content&lt;/b&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td class="rstext"&gt;Some text (Most likely will contain lots of HTML&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>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").</p> <p>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.</p> <p>My PHP...</p> <pre><code>&lt;?php $html = '&lt;html&gt; &lt;head&gt;&lt;/head&gt; &lt;body&gt; &lt;table&gt; &lt;tr&gt; &lt;td class="rsheader"&gt;&lt;b&gt;Header Content&lt;/b&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td class="rstext"&gt;Some text (Most likely will contain lots of HTML&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/body&gt; &lt;/html&gt;'; $dom = new DomDocument(); $dom-&gt;loadHtml($html); $xpath = new DomXpath($dom); $div = $xpath-&gt;query('//*[@class="rsheader"]')-&gt;item(0); echo $div-&gt;textContent; ?&gt; </code></pre> <p>If I do a print_r($div) I see this...</p> <pre><code>DOMElement Object ( [tagName] =&gt; td [schemaTypeInfo] =&gt; [nodeName] =&gt; td [nodeValue] =&gt; Header Content [nodeType] =&gt; 1 [parentNode] =&gt; (object value omitted) [childNodes] =&gt; (object value omitted) [firstChild] =&gt; (object value omitted) [lastChild] =&gt; (object value omitted) [previousSibling] =&gt; [nextSibling] =&gt; (object value omitted) [attributes] =&gt; (object value omitted) [ownerDocument] =&gt; (object value omitted) [namespaceURI] =&gt; [prefix] =&gt; [localName] =&gt; td [baseURI] =&gt; [textContent] =&gt; Header Content ) </code></pre> <p>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 :(</p> <p>Really hoping someone might be able to give me some help with this...</p> <p>Thanks in advance</p> <p>Paul</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload