Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    Regular Coder
    Join Date
    Jul 2010
    Location
    Sheffield
    Posts
    822
    Thanks
    93
    Thanked 18 Times in 18 Posts

    Which functions replaces line with r?

    I have this code to clean a string

    PHP Code:
    $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?

  • #2
    Regular Coder
    Join Date
    Oct 2010
    Location
    Florence, MS
    Posts
    484
    Thanks
    10
    Thanked 33 Times in 32 Posts
    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.

    PHP Code:
    $shout mysql_real_escape_string($_POST['shout']); 
    echo 
    $shout;
    $shout stripslashes($shout); 
    echo 
    $shout;
    $shout strip_tags($shout); 
    echo 
    $shout
    Last edited by Chris Hick; 09-14-2011 at 09:30 PM.
    Notice: If you post a problem and it gets fixed, please remember to go back and place it as solved. ;)
    I always recommend the HEAD First series of books for learning a new coding language. ^_^

  • #3
    Regular Coder
    Join Date
    Jul 2010
    Location
    Sheffield
    Posts
    822
    Thanks
    93
    Thanked 18 Times in 18 Posts
    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?

  • #4
    Regular Coder
    Join Date
    Oct 2010
    Location
    Florence, MS
    Posts
    484
    Thanks
    10
    Thanked 33 Times in 32 Posts
    Have you tried using the nl2br() function?? It takes all new lines in the string and replaces them with line breaks.
    Notice: If you post a problem and it gets fixed, please remember to go back and place it as solved. ;)
    I always recommend the HEAD First series of books for learning a new coding language. ^_^

  • Users who have thanked Chris Hick for this post:

    tomharto (09-15-2011)

  • #5
    Regular Coder
    Join Date
    Jul 2010
    Location
    Sheffield
    Posts
    822
    Thanks
    93
    Thanked 18 Times in 18 Posts
    Nope, ill take a look at it, thanks

  • #6
    Regular Coder
    Join Date
    Oct 2010
    Location
    Florence, MS
    Posts
    484
    Thanks
    10
    Thanked 33 Times in 32 Posts
    No problem! What it does is take new line characters and replaces them with break tags.
    Notice: If you post a problem and it gets fixed, please remember to go back and place it as solved. ;)
    I always recommend the HEAD First series of books for learning a new coding language. ^_^

  • #7
    Regular Coder
    Join Date
    Oct 2010
    Location
    Florence, MS
    Posts
    484
    Thanks
    10
    Thanked 33 Times in 32 Posts
    Did this work out for you, Tom?
    Notice: If you post a problem and it gets fixed, please remember to go back and place it as solved. ;)
    I always recommend the HEAD First series of books for learning a new coding language. ^_^

  • #8
    Regular Coder
    Join Date
    Jul 2010
    Location
    Sheffield
    Posts
    822
    Thanks
    93
    Thanked 18 Times in 18 Posts
    Yeah, worked a treat, thanks

  • #9
    Regular Coder
    Join Date
    Oct 2010
    Location
    Florence, MS
    Posts
    484
    Thanks
    10
    Thanked 33 Times in 32 Posts
    No problem. Glad to help.
    Notice: If you post a problem and it gets fixed, please remember to go back and place it as solved. ;)
    I always recommend the HEAD First series of books for learning a new coding language. ^_^


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •