Quick question:
What’s the best way to go about removing <br> and <br /> tags from the start and end of a $string?
I’m currently using this code, but it doesn’t appear to remove just <br> tags.
$str = preg_replace('{^(<br(\s*/)?>|ANDnbsp;)+}i', '', $str);
$str = preg_replace('{(<br(\s*/)?>|ANDnbsp;)+$}i', '', $str);
EDIT: Additional Information
This code is dealing with information that has been imported from an old CMS.
As such, I know that the only two tags I need to replace are <br> and <br />. Additionally, I am only looking to replace these tags at the very beginning and very end of a $string, not in between.
I don’t need to deal with any other tags; malformed HTML nor additional attributes.
Essentially I would simply like to expand the code I have suggested so that the <br> tags are replaced as well as <br />.
I apologise for not offering enough information to begin with.
Thanks in advance,
One possibility of regex is this:
So let’s make it clearer:
Explaining:
A good starting point: Regular expressions in Perl