PHP / MySQL - Unescaping strings?

lambada

New Member
Messages
2,444
Reaction score
0
Points
0
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

New Member
Messages
2,444
Reaction score
0
Points
0
Worked like a charm.

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

Thanks

lambada :)
 

Chris S

Retired
Messages
2,055
Reaction score
1
Points
38
np it was nothing for me. the sad thing is i actually had to remember that code. i was like what is that function...
 

dougyitbos

New Member
Messages
2
Reaction score
0
Points
0
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. ;)
 

Livewire

Abuse Compliance Officer
Staff member
Messages
18,169
Reaction score
216
Points
63
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 :)
 

dougyitbos

New Member
Messages
2
Reaction score
0
Points
0
ah...
Duh!

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

Very nice.
Thanks! :)
 

Livewire

Abuse Compliance Officer
Staff member
Messages
18,169
Reaction score
216
Points
63
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.
 
Top