3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = "Made in Switzerland, this stainless steel watch has single and double wrap interchangeable leather straps and is water resistant up to 30 meters<br><p><br></p>"; // $html = "<p>some thing</p>shitty p stuff<p>correct</p>\r\n<p>what about this</p>this is not correct\n"; // $html = "<p>some thing</p><p>shitty p stuff</p><p>correct</p><p>what about this</p>this is not correct"; // $html = "<p><a href=\"http://www.beataheuman.com/shop/\" title=\"www.beataheuman.com\">www.beataheuman.com</a>.</p><br />"; // $html = "ptest"; var_dump($html); // add <p></p> to the text if missing var_dump($html); // fix not closed paragraphs // $html = preg_replace('~(<p>.*?)([^</p>]<p>)~', '$1</p><p>', $html); var_dump($html); $html = preg_replace('~(\r\n|\n|\r)~s', '', $html); var_dump($html); // add into p the text in between paragraphs $html = preg_replace('~</p>([^<p>].+?)<p>~', '</p><p>$1</p><p>', $html); var_dump($html); // add into p the text after the last paragraph $html = preg_replace('~</p>((?!<p>).+)?$~Ds', '</p><p>$1</p>', $html, 1); var_dump($html); $html = preg_replace('~<p>(\W*)</p>~', '', $html); // $html = preg_replace('~^(<p>)?((?!</p>).*)(</p>)?$~A', '<p>$2</p>', $html); // if ($pPos = strpos($html, '<p>')) { // $html = '<p>' . substr($html, . '</p>'; // } // fix &nbsp; $html = html_entity_decode($html, null, 'UTF-8'); // change & to &amp; $html = preg_replace('/&(?!#?[a-z0-9]+;)/', '&amp;', $html); $paragraphPosition = strpos($html, '<p>'); if (0 !== $paragraphPosition) { $html = '<p>' . substr($html, 0, $paragraphPosition) . '</p>' . substr($html, $paragraphPosition); } var_dump($html);

preferences:
60.37 ms | 402 KiB | 5 Q