how can I remove excess <br> and
tags from the start and end of a string?
Thanks :)
The line break can be removed from string by using str_replace() function.
PHP provides an inbuilt function to remove the HTML tags from the data. The strip_tags() function is an inbuilt function in PHP that removes the strings form HTML, XML and PHP tags. It accepts two parameters. This function returns a string with all NULL bytes, HTML, and PHP tags stripped from a given $str.
Solution: It is not possible to remove just <p> tags without removing content inside.
try this:
$str = preg_replace('{^(<br(\s*/)?>| )+}i', '', $str); //from start
$str = preg_replace('{(<br(\s*/)?>| )+$}i', '', $str); //from end
that also gets XHTML <br />
and <br/>
forms
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With