无法从PHP中的字符串中删除所有换行符

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("
", "
", "");
    $newtext = str_replace($breaks, "", $body);

    echo $newtext;
   }
?>

Now let say I when filling out the form I press Shift+enter, that creates a in my string, but after submitting the form, $newtext still equals " ", shouldn't " " be removed because I'm replacing it with ""

Thanks.

The problem is that you're escaping the for MySQL first. Try this:

<?php 
   if (isset ($_POST['comment_form_submit'])) {
    $body = $_POST['body'];

    $breaks = array("
", "
", "");
    $newtext = str_replace($breaks, "", $body);

    $newtext = mysql_real_escape_string($newtext);

    echo $newtext;
   }
?>

Read about the escape function you're using to see why: http://php.net/mysql_real_escape_string

Please use this below code, Or copy paste the content in CK editor and replace the character which u want to replace...

 <?php
    $desc = trim(stripslashes($crw['Description']));
    $desc=str_replace(","," ",$desc);
    $desc=str_replace("
"," ",$desc);
    $desc=str_replace("
"," ",$desc);
    $desc=str_replace("<br>"," ",$desc);
    $desc=str_replace("<br />"," ",$desc);
    echo $desc; ?>