mmarif4u Posted June 15, 2007 Share Posted June 15, 2007 Hi guys, I have a system where a admin update news using textarea, he some use new line and white space and ' and : like symbols, now i pull these results from db, it give me the results which are below for example: \r\nCurrently YouTube has the English version, but half of YouTube viewers are from countries other than the United States, so there could be a Chinese version in the near future, he said.\r\nChen, 29, was born in Taiwan and emigrated with his family to the US at the age of 8. Malaysians join Tetra pak in celebrating world milk day.\r\nDon\\\'t miss the fun! These are the data which i pull out from db. It have \r\n and \\\ characters which ofcourse nobody want to show on site. I use nl2br function when puuling it out but no luck. I use mysql_real_escape_string when inserting it to db. So what function i use for these to show on the site correctly. Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/55688-solved-new-line-and-whitespaces/ Share on other sites More sharing options...
Orio Posted June 15, 2007 Share Posted June 15, 2007 I think the problem here is that you have magic_quotes turned on, and you also use mysql_real_escape_string(). This way, your strings get escaped twice. Try using this function instead of mysql_real_escape_string(), it'll will remove the slashes added by the magic_quotes and will convert your line breaks into br tags: <?php function escape_string ($text) { if(get_magic_quotes_gpc()) $text = stripslashes($text); $text = nl2br($text); $text = mysql_real_escape_string($text); return $text; } ?> Orio. Quote Link to comment https://forums.phpfreaks.com/topic/55688-solved-new-line-and-whitespaces/#findComment-275160 Share on other sites More sharing options...
r-it Posted June 15, 2007 Share Posted June 15, 2007 sorry for hijacking, i l337 av orio Quote Link to comment https://forums.phpfreaks.com/topic/55688-solved-new-line-and-whitespaces/#findComment-275176 Share on other sites More sharing options...
mmarif4u Posted June 15, 2007 Author Share Posted June 15, 2007 One thing more if i want to insert to db can i use multiple functions like: $text=mysql_real_escape_string(stripslashes($text1)); And this one: $text=mysql_real_escape_string(addslashes($text1)); Which is better to use for security issue. Quote Link to comment https://forums.phpfreaks.com/topic/55688-solved-new-line-and-whitespaces/#findComment-275178 Share on other sites More sharing options...
mmarif4u Posted June 16, 2007 Author Share Posted June 16, 2007 Thanks Orio, Ur function works. Quote Link to comment https://forums.phpfreaks.com/topic/55688-solved-new-line-and-whitespaces/#findComment-275637 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.