As the title says I have a string like this:
$string = "Hello World<br>hello world<br><br>";
I would like to get rid of the <br>
s at the end of the string so it looks as follows:
$string = "Hello World<br>hello world";
I tried this:
preg_replace('/^(<br>)*/', "", $string);
but it didn't work. Maybe someone knows the right regex.
You're close, you used ^ at the start of the regexp, which means "match the start of the string." You want $ at the end, which means, "Match the end of the string."
preg_replace('/(<br>)+$/', '', $string);
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