SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    May 2004
    Location
    London
    Posts
    155
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    stripslashes() works only sometimes

    Hi there

    Am I right in thinking that the stripslashes() function only works once on the same bit of text in the same browsing session?

    I've a text box on my site where people enter in comments then can preview them (on another page) before submitting them to my database.

    I use

    PHP Code:
    <?php

    $TheComment 
    stripslashes($_POST['comments']); 

    echo 
    $TheComment;

    ?>
    It's similar to when you preview your post before submitting on this forum. The problem I find is that stripslashes() works the first time around but if the person wants to amend what they've written and preview a second (or third) time etc. stripslashes() doesn't work.

    For example I'm appears as I\'m etc.

    If so (it only works once) is there any work around?

    many thanks


    Juan.

  2. #2
    Umm. PHP Guru....Naaaah jaswinder_rana's Avatar
    Join Date
    Jul 2004
    Location
    canada
    Posts
    3,193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the code you posted is all on the page. if not then please post the complete code.

  3. #3
    SitePoint Zealot
    Join Date
    May 2004
    Location
    London
    Posts
    155
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have other code on the page but it but it's just html that won't interfere with the php processing.

    As I say it seems that stripslashes works first time around but not on any subsequent previews on what's been written into the textbox. Why might that be?

  4. #4
    SitePoint Enthusiast nick b's Avatar
    Join Date
    Jan 2005
    Location
    Austin, TX
    Posts
    61
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need to be careful that PHP is not inserting the slashes again. I had issues with this where I needed to strip the slashes, display the variable, and then use the variable again in a way that added the slashes back in. In this case I just restripped and it seemed to work okay.

    Could this be something that might be occuring on your page?
    Nick Bartkowiak
    SerenityDigital.com

  5. #5
    Umm. PHP Guru....Naaaah jaswinder_rana's Avatar
    Join Date
    Jul 2004
    Location
    canada
    Posts
    3,193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well even if the PHP is doing that (with magic_quotes) he is just strippping them off (which is not quite ok because user might have added them on purpose and if magic_quotes are off then it would take those slashes off too but that's different story).

    so, again it'd be good if you can post the whole page even the HTML so we can test and see.


Bookmarks

Posting Permissions

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