Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Can be done with <a href="http://www.php.net/manual/en/class.domdocument.php" rel="nofollow noreferrer">DOMDocument</a> class within PHP using the <a href="http://www.php.net/manual/en/domdocument.loadhtml.php" rel="nofollow noreferrer">DOMDocument::loadHTML</a>() &amp; <a href="http://www.php.net/manual/en/domdocument.normalizedocument.php" rel="nofollow noreferrer">DOMDocument::normalizeDocument</a>() methods.</p> <pre><code>&lt;?php $html = '&lt;div&gt;&lt;p&gt;The quick brown &lt;a href=""&gt;fox jumps'; $DDoc = new DOMDocument(); $DDoc-&gt;loadHTML($html); $DDoc-&gt;normalizeDocument(); echo $DDoc-&gt;saveHTML(); ?&gt; </code></pre> <p>OutPuts:</p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"&gt; &lt;html&gt;&lt;body&gt;&lt;div&gt;&lt;p&gt;The quick brown &lt;a href=""&gt;fox jumps&lt;/a&gt;&lt;/p&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt; </code></pre> <p>From there, just <a href="http://www.php.net/manual/en/function.substr.php" rel="nofollow noreferrer">substr</a> &amp; <a href="http://www.php.net/manual/en/function.strpos.php" rel="nofollow noreferrer">strpos</a> away the html that you don't want, like so:</p> <pre><code>&lt;?php $html = '&lt;div&gt;&lt;p&gt;The quick brown &lt;a href=""&gt;fox jumps'; $DDoc = new DOMDocument(); $DDoc-&gt;loadHTML($html); $DDoc-&gt;normalizeDocument(); $html = $DDoc-&gt;saveHTML(); # Remove Everything Before &amp; Including The Opening HTML &amp; Body Tags. $html = substr($html, strpos($html, '&lt;html&gt;&lt;body&gt;') + 12); # Remove Everything After &amp; Including The Closing HTML &amp; Body Tags. $html = substr($html, 0, -14); echo $html; ?&gt; </code></pre>
    singulars
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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