Jump to content

Recommended Posts

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.

 

Link to comment
https://forums.phpfreaks.com/topic/55688-solved-new-line-and-whitespaces/
Share on other sites

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.

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.

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.