• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

Changing Characters in a Variable

Niaad

New Member
I wrote a script that lets people login and edit their profiles which are stored in a MySQL database.

One of the fields is Quote...and I've noticed a very annoying problem. When people go to do...

"My Quote"

...and then click submit, it doesn't get updated, since MySQL rejects it. The users have to put a \ to escape the " first. Now that is a very easy solution in itself, but lets face it, that's annoying. Very, VERY annoying.

I remember in CGI you could transform characters in variables by doing this:

$var =~ tr/a/b/;

That would change all the letter a's in the variable to letter b's, basically. I tried that in PHP, and it didn't work.

I want to change all ' and " to \' and \" without making the users do it. Is this possible with PHP? If so, how?
 
Back
Top