Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

php \ escap special character problem

Options
  • 02-07-2007 4:35pm
    #1
    Registered Users Posts: 94 ✭✭


    Im trying to update an ms sql db but im strugglin with the pesky single quote. To update the db i need to covert a " ' " to " '' ". Then i try this i end up with a \. Really annoying.

    $storyfixed = eregi_replace("'", "''", $story);

    and


    $storyfixed = eregi_replace('\'', '\'\'', $story);

    are both producing the same problem

    "help me'o" gets transformed into:--> 1, 'help me\''o', 'blank', CURRENT_TIMESTAMP

    Anybody got any ideas?


Comments

  • Closed Accounts Posts: 30 Mr. Magoo


    This should do it

    $storyfixed = str_replace("'",'"',$story);


  • Registered Users Posts: 94 ✭✭sinkingfish


    Thanks for the help, we were both close...

    this worked : $storyfixed = str_replace("\'","''",$story);

    A little bit of trial and error!


  • Registered Users Posts: 568 ✭✭✭phil


    There's an addslashes() function in PHP which does this. You should be aware of SQL injection vulnerabilities you are opening yourself up to whenever you insert anything into an SQL database from user input fields.

    It's normally wiser to use some of the database abstraction libraries knocking around like adodb.


  • Registered Users Posts: 804 ✭✭✭TimTim


    phil wrote:
    There's an addslashes() function in PHP which does this. You should be aware of SQL injection vulnerabilities you are opening yourself up to whenever you insert anything into an SQL database from user input fields.

    It's normally wiser to use some of the database abstraction libraries knocking around like adodb.

    While I don't claim to be an anyway decent php coder. I've read/heard using addslashes() and stripslashes() in a php application is just a plain stupid thing to do.

    If you are going to be using user input and putting it into a sql database mysql_real_escape_string() would better thing to use.


  • Registered Users Posts: 1,393 ✭✭✭Inspector Gadget


    I'd suggest the adodb library too (it's very handy, in my opinion) - it's got a method called qstr() that does exactly this.

    Hope this helps,
    Gadget


  • Advertisement
Advertisement