The Joyent Community

A place where the Joyent community can gather, help each other out, and stay informed.

You are not logged in.

#1 2007-03-02 16:11:42

ngungo
a monpageur
Registered: 2004-06-01
Posts: 3468
Website  Expertise

Extra escape character

I use php function file_put_contents() to write text to a file. It works fine in my TxD host but kinda funny on my localhost (XAMPP on Windows XP). It writes extra escape char \ in front of single quote char.

Any hint to cure this would be appreciated.

Offline

 

#2 2007-03-02 18:03:27

ngungo
a monpageur
Registered: 2004-06-01
Posts: 3468
Website  Expertise

Re: Extra escape character

It seems that I have to make use of stripslashes() function. I will try that. If it does not work I will post more of what and why here.

Offline

 

#3 2007-03-02 18:17:59

juxta
El Jefe
From: California
Registered: 2005-10-28
Posts: 499
Website  Expertise

Re: Extra escape character

ngungo, where's the text that you are writing originating from? It sounds like a magic_quotes issue.

stripslashes(), while it may work, will cause adverse effects the slashes aren't occurring on all servers.

Offline

 

#4 2007-03-02 18:20:05

juxta
El Jefe
From: California
Registered: 2005-10-28
Posts: 499
Website  Expertise

Re: Extra escape character

Assuming the text you are inputting is coming from GET, POST, or the like, check your local php.ini file for the magic_quotes_gpc setting. It should be off.

Offline

 

#5 2007-03-02 18:58:51

ngungo
a monpageur
Registered: 2004-06-01
Posts: 3468
Website  Expertise

Re: Extra escape character

Right. You're right. Thanks!

Offline

 

#6 2007-03-02 19:47:07

ngungo
a monpageur
Registered: 2004-06-01
Posts: 3468
Website  Expertise

Re: Extra escape character

juxta,
It does not seem working.
I edited the php.ini then stopped & start Apache. Is that right? What else I have to do?

Offline

 

#7 2007-03-02 19:50:46

Andy
Dabbler
From: London
Registered: 2005-01-15
Posts: 1177
Website  Expertise

Re: Extra escape character

To check what it's set to, use get_magic_quotes_gpc().


— Andy (andrewlkho)

Offline

 

#8 2007-03-02 20:43:00

juxta
El Jefe
From: California
Registered: 2005-10-28
Posts: 499
Website  Expertise

Re: Extra escape character

Check using phpinfo(); or what Andy mentioned to make sure it is in fact disabling it. I've had a case where I was editing the wrong php.ini before...

Also, if there are any other magic_quote setting turn them off as well. Magic quotes are evil quotes.

Offline

 

#9 2007-03-02 20:44:31

juxta
El Jefe
From: California
Registered: 2005-10-28
Posts: 499
Website  Expertise

Re: Extra escape character

If that is the problem and you can't turn it off here's some code that should compensate:

Code:

if (get_magic_quotes_gpc()) {

$_GET = array_map('stripslashes', $_GET); $_POST = array_map('stripslashes', $_POST);
}

Offline

 

#10 2007-03-02 20:56:40

ngungo
a monpageur
Registered: 2004-06-01
Posts: 3468
Website  Expertise

Re: Extra escape character

Working! Working! Thanks! Thanks!!!
I never had a chance to use the array_map() before. This is my first. Excited. HAHAH!!!

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson