15
If a string ends with an HTML tag, for example <br>
or <hr>
, when making use of the PHP function rtrim() to clear said tag, in cases where the letter immediately before is an "r", the same is removed in conjunction 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;
Upshot:
Bubu went to lunch
Bubu went to lunch
Bubu went to lunch (correct)
Bubu went to lunch
Question
How to circumvent this issue so that in the practical case where the condition above occurs, the result does not differ from the expected?
+1 for explaining why it happens
– Jorge B.