SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Wizard
    Join Date
    Mar 2008
    Location
    United Kingdom
    Posts
    1,285
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Replace ' with \' help - urgent please

    How do I do this with PHP?

    Is it just $text = str_replace("'","\'", $text); ?


    Many thanks for any help.

  2. #2
    SitePoint Zealot
    Join Date
    Mar 2008
    Posts
    113
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have you tried it?
    It works on my php.

  3. #3
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Wouldn't the native addslashes and stripslashes be more appropriate?
    PHP Code:
    <?php
    $sString 
    addslashes("'''''''"); 
    echo 
    $sString#\'\'\'\'\'\'\'
    $sString stripslashes($sString);
    echo 
    $sString#'''''''
    ?>
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  4. #4
    SitePoint Wizard
    Join Date
    Mar 2008
    Location
    United Kingdom
    Posts
    1,285
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Aaaah. Thanks guys.

    Basically I'm using the TinyMCE editor to insert text in <textarea>'s and if my text was:

    Hi, I'm Michael

    then it would still try to enter Hi, I'm Michael into the db, rather than making it Hi, I\'m Michael.

    So should I try $descr = addslashes($descr); to fix this ?

    I'm escaping all my data and it works great, except those using the TinyMCE editor.

  5. #5
    SitePoint Wizard
    Join Date
    Mar 2008
    Location
    United Kingdom
    Posts
    1,285
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Heh, my first one did work. How about that
    Yep, it definitely works. I'm chuffed.

    I've got a few questions I might try to get answered in the next few days, to get my head around slashes and such.


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
  •