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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

php \ escap special character problem

  • 02-07-2007 3:35pm
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 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, Registered Users 2 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, Registered Users 2 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, Registered Users 2 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