...

View Full Version : Which functions replaces line with r?



tomharto
09-14-2011, 10:18 PM
I have this code to clean a string


$shout = mysql_real_escape_string($_POST['shout']);
$shout = stripslashes($shout);
$shout = strip_tags($shout);

But if i put

Test Posting
In the
Shoutbox

It changes it to Test PostingnIn thenShoutbox

Which of those functions in my code is doing that?

Chris Hick
09-14-2011, 10:26 PM
Tom, I know that mysql_escape_string will escape the new line character. If I were you I would echo out the values after each clean. So, do this and see what the results are. It should then tell you what each one did to the string at each stage.

EDIT: Also, you must remember strip_tags will strip the html from the input.



$shout = mysql_real_escape_string($_POST['shout']);
echo $shout;
$shout = stripslashes($shout);
echo $shout;
$shout = strip_tags($shout);
echo $shout;

tomharto
09-14-2011, 10:36 PM
Yeah it was the mysql one, however if i submit that string

Test Posting
In the
Shoutbox

Once its outputted its all on one line, is there any way to keep the formatting?

Chris Hick
09-14-2011, 10:55 PM
Have you tried using the nl2br() function?? It takes all new lines in the string and replaces them with line breaks.

tomharto
09-14-2011, 11:19 PM
Nope, ill take a look at it, thanks :)

Chris Hick
09-14-2011, 11:22 PM
No problem! :thumbsup: What it does is take new line characters and replaces them with break tags.

Chris Hick
09-15-2011, 11:33 PM
Did this work out for you, Tom?

tomharto
09-15-2011, 11:33 PM
Yeah, worked a treat, thanks :)

Chris Hick
09-15-2011, 11:34 PM
No problem. :thumbsup: Glad to help.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum