I have a form that allows the user to enter what character to trim from the end of a string. Here's a simple example. The form submits back to itself and alters the string Testing 123, If you enter a comma into the form, you get back Testing 123 (comma is removed). But what if that same string had a line break after the comma. I want to be able to enter , into the form and have it return Testing 123 So both the empty line and the comma are trimmed. I assume it has to be escaped, but I can't figure it out. I've tried removeslashes, htmlspecialchars, urldecode. I can't seem to get it.
<?php
if (empty($_POST['trim'])) {
echo "<form method='post' action='".$_SERVER["PHP_SELF"]."'>
<input type='text' name='trim'>
<input type='submit' value='submit'>
</form>";exit;}
$str="testing 123,
";
$str=rtrim($str,$_POST['trim']);
echo $str;
?>