+ Reply to Thread
Results 1 to 10 of 10

Thread: PHP / MySQL - Unescaping strings?

  1. #1
    lambada's Avatar
    lambada is offline x10 Elder lambada is an unknown quantity at this point
    Join Date
    Mar 2006
    Location
    Caister, Gt Yarmouth, Norfolk, ENGLAND
    Posts
    1,222

    Question PHP / MySQL - Unescaping strings?

    HI,

    I have a slight problem in that everytime I use the PEAR DB place-holder function (an automantic mysql_real_escape_string) When I next use SELECT to retrieve the data froim the Database The content looks like: "It\'s escaped". Is there an easy way to unescape the strings either through standard php / MySQL or the PEAR DB API?

    Thanks

    lambada
    Lambada - the former Account Manager (before I resigned)




  2. #2
    Chris S's Avatar
    Chris S is offline Retired Chris S is an unknown quantity at this point
    Join Date
    Mar 2005
    Posts
    1,036

    Re: PHP / MySQL - Unescaping strings?

    php - stripslashes($var);

    I would love to change the world, but they won't give me the source code

  3. #3
    lambada's Avatar
    lambada is offline x10 Elder lambada is an unknown quantity at this point
    Join Date
    Mar 2006
    Location
    Caister, Gt Yarmouth, Norfolk, ENGLAND
    Posts
    1,222

    Re: PHP / MySQL - Unescaping strings?

    Worked like a charm.

    It's amazing how much stuff a 'through' book can miss out - that being just one example.

    Thanks

    lambada
    Lambada - the former Account Manager (before I resigned)




  4. #4
    Chris S's Avatar
    Chris S is offline Retired Chris S is an unknown quantity at this point
    Join Date
    Mar 2005
    Posts
    1,036

    Re: PHP / MySQL - Unescaping strings?

    np it was nothing for me. the sad thing is i actually had to remember that code. i was like what is that function...

    I would love to change the world, but they won't give me the source code

  5. #5
    dougyitbos is offline x10Hosting Member dougyitbos is an unknown quantity at this point
    Join Date
    Feb 2008
    Posts
    2

    Re: PHP / MySQL - Unescaping strings?

    What if the data you are putting/pulling from the Database has HTML code in it?
    Just removing slashes could be a bad idea.

    Anybody know of a function that unescapes intelligently in that regard?
    I hate the idea of writing one when someone ha likely done it. ;)

  6. #6
    Livewire's Avatar
    Livewire is offline Abuse Compliance Officer Livewire is a glorious beacon of lightLivewire is a glorious beacon of light
    Join Date
    Jun 2005
    Location
    Behind a keyboard.
    Posts
    8,998

    Re: PHP / MySQL - Unescaping strings?

    Quote Originally Posted by dougyitbos View Post
    What if the data you are putting/pulling from the Database has HTML code in it?
    Just removing slashes could be a bad idea.

    Anybody know of a function that unescapes intelligently in that regard?
    I hate the idea of writing one when someone ha likely done it. ;)
    Still shouldn't matter, html uses / slashes, whereas escaped strings use \

    So <body>it\'s working</body> should still only lose the \, so it'd become <body>it's working</body>.


    Should it happen to cut that slash out, you could just use one of the string replace functions (can't remember which right now) and replace "\" with an empty string


    TOS breakers will be suspended regardless of race, creed, national origin, hair color, or favorite food. Thanks for your understanding!

  7. #7
    dougyitbos is offline x10Hosting Member dougyitbos is an unknown quantity at this point
    Join Date
    Feb 2008
    Posts
    2

    Re: PHP / MySQL - Unescaping strings?

    ah...
    Duh!

    I was thinking that the strip slashes was non specific and removed both.

    Very nice.
    Thanks!

  8. #8
    Livewire's Avatar
    Livewire is offline Abuse Compliance Officer Livewire is a glorious beacon of lightLivewire is a glorious beacon of light
    Join Date
    Jun 2005
    Location
    Behind a keyboard.
    Posts
    8,998

    Re: PHP / MySQL - Unescaping strings?

    I'm not positive that it only removes one either though; I'm just guessing that it wouldn't since escaped strings use \, and in normal text / doesn't do anything special.


    I'll see if I can test that later this evening and see what it does.


    TOS breakers will be suspended regardless of race, creed, national origin, hair color, or favorite food. Thanks for your understanding!

  9. #9
    Chris S's Avatar
    Chris S is offline Retired Chris S is an unknown quantity at this point
    Join Date
    Mar 2005
    Posts
    1,036

    Re: PHP / MySQL - Unescaping strings?

    it only removes \

    I would love to change the world, but they won't give me the source code

  10. #10
    Livewire's Avatar
    Livewire is offline Abuse Compliance Officer Livewire is a glorious beacon of lightLivewire is a glorious beacon of light
    Join Date
    Jun 2005
    Location
    Behind a keyboard.
    Posts
    8,998

    Re: PHP / MySQL - Unescaping strings?

    Quote Originally Posted by Chris S View Post
    it only removes \
    There you go. Thanks for saving me on that too - XAMPP just decided to go chest-up right as I was ready to test it >_<


    TOS breakers will be suspended regardless of race, creed, national origin, hair color, or favorite food. Thanks for your understanding!

+ Reply to Thread

Similar Threads

  1. [PHP] MySQL and PHP
    By Bryon in forum Tutorials
    Replies: 43
    Last Post: 03-24-2011, 07:27 AM
  2. tons of PHP Resources
    By Chris S in forum Scripts & 3rd Party Apps
    Replies: 10
    Last Post: 01-16-2009, 10:07 AM
  3. Unstand PHP?
    By o0slowpaul0o in forum Tutorials
    Replies: 8
    Last Post: 01-07-2008, 09:16 PM
  4. Have a problem with my forum
    By tikloos in forum Scripts & 3rd Party Apps
    Replies: 43
    Last Post: 01-19-2006, 01:14 AM
  5. Php And Mysql Forum Rephrased!
    By maddude in forum Scripts & 3rd Party Apps
    Replies: 7
    Last Post: 04-05-2005, 12:14 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers