Strange PHP Behavior

Discussion in 'PHP' started by NateJ, Apr 14, 2009.

  1. #1
    For some unknown reason, when ever i enter a word that has a ' in it such as "Can't" it will display as "Can\'t"

    Now, my question is, How do i stop this from happening because it's becoming rather irratating now.

    Any help will be appreciated.

    Thanks.
     
    NateJ, Apr 14, 2009 IP
  2. emed

    emed Peon

    Messages:
    70
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #2
    i think your server have magic quotes enabled

    http://www.php.net/magic_quotes
    you can disable magic quotes or you can use stripslashes
    <?php
    if(get_magic_quotes_gpc()){
    $_GET['variable'] = stripslashes($_GET['variable']);
    $_POST['variable2'] = stripslashes($_POST['variable2']);
    }
    ?>
    PHP:
     
    emed, Apr 14, 2009 IP
  3. mehdi

    mehdi Peon

    Messages:
    258
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #3
    lets say, $var is the variable. try this code
    
    $newvar = stripslashes($var);
    
    PHP:
    This will remove slashes from the string.

    Thanks, hope it helps.
     
    mehdi, Apr 14, 2009 IP
  4. NateJ

    NateJ Active Member

    Messages:
    240
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #4
    It still displays as "Can't".

    This is part of the script:

     
    NateJ, Apr 14, 2009 IP
  5. NateJ

    NateJ Active Member

    Messages:
    240
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #5
    It turns out that my server, did infact, have Magic Quotes enabled, i've now disabled it and the problem seems to be resolved.

    Thanks for your speedy responses.
     
    NateJ, Apr 14, 2009 IP
  6. mehdi

    mehdi Peon

    Messages:
    258
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Thats cool, good to hear that everything is fine now.
     
    mehdi, Apr 15, 2009 IP