<?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
$html = html_entity_decode($html, null, 'UTF-8');
// change & to &
$html = preg_replace('/&(?!#?[a-z0-9]+;)/', '&', $html);
$paragraphPosition = strpos($html, '<p>');
if (0 !== $paragraphPosition) {
$html = '<p>' . substr($html, 0, $paragraphPosition) . '</p>' . substr($html, $paragraphPosition);
}
var_dump($html);
string(159) "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>"
string(159) "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>"
string(159) "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>"
string(159) "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>"
string(159) "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>"
string(166) "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><p></p>"
Deprecated: html_entity_decode(): Passing null to parameter #2 ($flags) of type int is deprecated in /in/igRGr on line 35
string(166) "<p>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><p><br></p>"
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
string(159) "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>"
string(159) "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>"
string(159) "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>"
string(159) "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>"
string(159) "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>"
string(166) "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><p></p>"
Deprecated: html_entity_decode(): Passing null to parameter #2 ($flags) of type int is deprecated in /in/igRGr on line 35
string(166) "<p>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><p><br></p>"
string(159) "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>"
string(159) "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>"
string(159) "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>"
string(159) "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>"
string(159) "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>"
string(166) "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><p></p>"
string(166) "<p>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><p><br></p>"