3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $str = '<p>\' ‘ ’ ‚ " “ ” „ &amp;amp; © ® ™ ° &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</p>'; echo clean($str); echo PHP_EOL.PHP_EOL; $htmlent = htmlentities($str, ENT_HTML5 | ENT_QUOTES, 'UTF-8'); echo $htmlent; echo PHP_EOL.PHP_EOL; echo htmlentity_decode($htmlent); function clean($str_clean, $strict_clean = true, $punct_clean = true) { $base_pool = array( '‘' => '&lsquo;', '’' => '&rsquo;', '‚' => '&sbquo;', '“' => '&ldquo;', '”' => '&rdquo;', '„' => '&bdquo;', '©' => '&copy;', '®' => '&reg;', '™' => '&trade;', '°' => '&deg;', '•' => '&bull;', '–' => '&ndash;', '—' => '&mdash;', '…' => '&#8230;', '¼' => '&#188;', '½' => '&#189;', '¾' => '&#190;', '‰' => '&#8240;', '±' => '&#177;', '†' => '&#8224;', '‡' => '&#8225;', '&amp;amp;' => '&amp;', '&nbsp;' => ' ' ); $strict_pool = array( '\'' => '&#39;', '"' => '&quot;', "\r" => ' ', "\n" => ' ', "\t" => ' ' ); // if strict param is true we will clean harder (default true) if ($strict_clean) { $base_pool = array_merge($strict_pool, $base_pool); } foreach ($base_pool as $key => $value) { $str_clean = str_replace($key, $value, $str_clean); // iterate through pool key => values and replace in $str_clean } // if punct param is true we will add spaces after punctuation (default true) if ($punct_clean) { $str_clean = preg_replace('/([!?,.])(\S)/', '$1 $2', $str_clean); // parse punctuation and add trail space } $str_clean = preg_replace("/\s+/", ' ', $str_clean); // filter multiple spaces into single return $str_clean; }
based on BSYms
Output for 7.0.0 - 7.2.0
<p>&#39; &lsquo; &rsquo; &sbquo; &quot; &ldquo; &rdquo; &bdquo; &amp; &copy; &reg; &trade; &deg; </p> &lt;p&gt;&apos; &OpenCurlyQuote; &rsquo; &sbquo; &quot; &OpenCurlyDoubleQuote; &rdquo; &bdquo; &amp;amp&semi;amp&semi; &copy; &reg; &trade; &deg; &amp;nbsp&semi; &amp;nbsp&semi; &amp;nbsp&semi; &amp;nbsp&semi; &amp;nbsp&semi; &amp;nbsp&semi;&lt;&sol;p&gt; Fatal error: Uncaught Error: Call to undefined function htmlentity_decode() in /in/Y0RMq:15 Stack trace: #0 {main} thrown in /in/Y0RMq on line 15
Process exited with code 255.
Output for 5.4.12 - 5.6.28
<p>&#39; &lsquo; &rsquo; &sbquo; &quot; &ldquo; &rdquo; &bdquo; &amp; &copy; &reg; &trade; &deg; </p> &lt;p&gt;&apos; &OpenCurlyQuote; &rsquo; &sbquo; &quot; &OpenCurlyDoubleQuote; &rdquo; &bdquo; &amp;amp&semi;amp&semi; &copy; &reg; &trade; &deg; &amp;nbsp&semi; &amp;nbsp&semi; &amp;nbsp&semi; &amp;nbsp&semi; &amp;nbsp&semi; &amp;nbsp&semi;&lt;&sol;p&gt; Fatal error: Call to undefined function htmlentity_decode() in /in/Y0RMq on line 15
Process exited with code 255.
Output for 5.3.22 - 5.3.29
<p>&#39; &lsquo; &rsquo; &sbquo; &quot; &ldquo; &rdquo; &bdquo; &amp; &copy; &reg; &trade; &deg; </p> Notice: Use of undefined constant ENT_HTML5 - assumed 'ENT_HTML5' in /in/Y0RMq on line 9 &lt;p&gt;&#039; &lsquo; &rsquo; &sbquo; &quot; &ldquo; &rdquo; &bdquo; &amp;amp;amp; &copy; &reg; &trade; &deg; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/p&gt; Fatal error: Call to undefined function htmlentity_decode() in /in/Y0RMq on line 15
Process exited with code 255.