\n\r Not removed by PHP functions
On my home page, I display some info about the hikes (it is a hiking site) and embarassinlgy, the \r\n characters still show up.
I do these functons
$hike_description = htmlspecialchars ($hike_description);
$hike_description = nl2br($hike_description);
A开发者_Go百科nd still those characters do not go away. You can take a look yourself at http://www.comehike.com
Would you know what is the proper way to get rid of the \r\n characters? You can see it happening in the "Upcoming Hikes" section...on the 3rd hike.
Thanks!
In your case, the following will work:
$hike_description = str_replace ( "\\r\\n","<br />", $hike_description);
The text \r\n
is literal, rather than control characters.
Try manually replacing the sequence
str_replace( "\r\n", "<br />", $hike_description );
The \n\r
in your page are not escape sequences... They are actually a \
character followed by a n
character followed by a \
character followed by a r
character.
In your database, you should store that as the actual characters, not the escape sequences. Then, calling nl2br()
will work as expected.
Yes, you can do a str_replace()
, however, you should instead fix the encoding of your data in your database. It will save you trouble in the future.
精彩评论