I’ve got a basic textarea form. What i’m trying to do is remove all line breaks from the textarea after its been submitted.
Here’s my PHP:
<?php
if (isset ($_POST['comment_form_submit'])) {
$body = mysql_real_escape_string($_POST['body']);
$breaks = array("\r\n", "\n", "\r");
$newtext = str_replace($breaks, "", $body);
echo $newtext;
}
?>
Now let say I when filling out the form I press Shift+enter, that creates a \n in my string, but after submitting the form, $newtext still equals “\n”, shouldn’t “\n” be removed because I’m replacing it with “”
Thanks.
The problem is that you’re escaping the
\nfor MySQL first. Try this:Read about the escape function you’re using to see why: http://php.net/mysql_real_escape_string