If a string ends with an HTML tag, for example <br>
or <hr>
, when making use of the PHP function # to clean the tag, in cases where the letter immediately before is an "r", it is removed together with the HTML tag:
Example
$string = "bubu foi almoçar<br>";
echo rtrim($string, "<br>") . PHP_EOL;
$string = "bubu foi almoçar<hr>";
echo rtrim($string, "<hr>") . PHP_EOL;
$string = "bubu foi almoçar!";
echo rtrim($string, "!") . PHP_EOL;
$string = "bubu foi almoçar";
echo rtrim($string, "<br>") . PHP_EOL;
Result:
Bubu was having lunch
Bubu was having lunch
Bubu went to lunch (correct)
Bubu was having lunch
Question
How to work around this issue so that in the practical case where the condition above occurs, the result does not come different than expected?