Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP - getting inner HTML code of two elements
    text
    copied!<p>I am currently in a transition process, I want to make CMS of my existing website. Until now (for a few years) I was generating and saving complete html files, and I want to store content of those pages in a database. My luck, I think, is that two elements I want to take from each html are unique inside one html file and same in all files. I have tried this:</p> <pre><code>if ($handle = opendir('.')) { while (false !== ($entry = readdir($handle))) { if ($entry != "." &amp;&amp; $entry != "..") { $string= file_get_contents($entry); $pattern = "/&lt;h1&gt;(.*?)&lt;\/h1&gt;/"; preg_match_all($pattern, $string, $uname); $pattern = '/&lt;p class=\"user_info\"&gt;&lt;strong&gt;(.*?)&lt;\/strong&gt;&lt;\/p&gt;/'; preg_match_all($pattern, $string, $udesc); echo "NAME: ".$uname[1][0]."&lt;br&gt;"; echo "DESC: ".$udesc[1][0]."&lt;br&gt;"; //MYSQL SAVING WILL GO HERE } } closedir($handle); } </code></pre> <p>Above code extracts (h1)NAME(/h1) (imagine that (==&lt; and )==>) part, but not (p class="user_info")(strong)CONTENT(/strong)(/p) part, it is just blank.</p> <p>I have also tried different method:</p> <pre><code>if ($handle = opendir('.')) { while (false !== ($entry = readdir($handle))) { if ($entry != "." &amp;&amp; $entry != "..") { $string= file_get_contents($entry); $doc = new DOMDocument(); $doc-&gt;loadHTML($string); $h1 = $doc-&gt;getElementsByTagName('h1')-&gt;item(0)-&gt;textContent; echo "NAME: ".$h1."&lt;br&gt;"; $p = $doc-&gt;saveHtml($doc-&gt;getElementsByTagName('p')-&gt;item(0)); // $p = $doc-&gt;getElementsByTagName('p')-&gt;item(0)-&gt;textContent; loads content, just without html tags, so I can not use it... :S echo "DESC: ".$p."&lt;br&gt;"; //MYSQL SAVING WILL GO HERE } } closedir($handle); } </code></pre> <p>Above code works, but not as expected. I need complete HTML code of paragraph, not just text. I have also tried $doc->savehtml(), still nothing.</p> <p>Please help, and thanks in advance! </p>
 

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