开发者

How can I replace \r\n with a line break when I echo?

开发者 https://www.devze.com 2023-02-09 02:12 出处:网络
I am protecting my string using this code to insert it into the database: function protect($string){ $string = mysql_real_escape_string($string);

I am protecting my string using this code to insert it into the database:

function protect($string){

    $string = mysql_real_escape_string($string);

    return $str开发者_运维百科ing;
}

I then unprotect it using this code so that I can echo it out from the database:

function echoprotect($string){

    $string = nl2br($string);
    $string = stripslashes($string);

    return $string;
}

The nl2br doesn't seem to work and I don't know why. The output I get is:

HellornrnThe content ect...

instead of:

hello

the content ect...


From the mysql_real_escape_string manual:

mysql_real_escape_string() calls MySQL's library function mysql_real_escape_string, which prepends backslashes to the following characters: \x00, \n, \r, \, ', " and \x1a.

So nl2br() is ignoring the escaped \n's and \r's, methinks.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号