Raised This Month: $51 Target: $400
 12% 

[PHP] replace quotes


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
[ --<-@ ] Black Rose
ANNIHILATED
Join Date: Sep 2005
Location: Stockholm, Sweden.
Old 08-26-2009 , 13:05   [PHP] replace quotes
Reply With Quote #1

I wan't to replace " with \" and ' with \' for easy conversion from html->php.

How would I do it? str_replace("\"", "\\\"", $whatever); doesn't work...
[ --<-@ ] Black Rose is offline
alexinno
Senior Member
Join Date: Mar 2007
Location: C:\
Old 08-26-2009 , 15:01   Re: [PHP] replace quotes
Reply With Quote #2

you should use preg_replace function
__________________

[IMG]http://img188.**************/img188/5787/banner2rcw.png[/IMG]
alexinno is offline
8088
Veteran Member
Join Date: Jan 2008
Old 08-26-2009 , 18:15   Re: [PHP] replace quotes
Reply With Quote #3

Why preg_replace?

In this case I would use addslashes.
PHP Code:
$whatever=addslashes($whatever); 
__________________
steamID converter with OpenSearch browser plugin
8088 is offline
alexinno
Senior Member
Join Date: Mar 2007
Location: C:\
Old 08-26-2009 , 18:31   Re: [PHP] replace quotes
Reply With Quote #4

i didn't know about addslashes
__________________

[IMG]http://img188.**************/img188/5787/banner2rcw.png[/IMG]
alexinno is offline
Styles
Veteran Member
Join Date: Jul 2004
Location: California
Old 08-26-2009 , 19:03   Re: [PHP] replace quotes
Reply With Quote #5

strip slashes
mysql_escape_string
Styles is offline
Send a message via AIM to Styles
crazyeffect
Veteran Member
Join Date: Jul 2008
Location: Belgium
Old 08-26-2009 , 19:04   Re: [PHP] replace quotes
Reply With Quote #6

He got 3 ways to do it already

Lets try those 3 now xD
__________________
crazyeffect is offline
Send a message via MSN to crazyeffect
8088
Veteran Member
Join Date: Jan 2008
Old 08-26-2009 , 19:21   Re: [PHP] replace quotes
Reply With Quote #7

Quote:
Originally Posted by styles View Post
strip slashes
Actually strip_slashes does the opposite of what Superiority asked for.
Quote:
mysql_escape_string
This is deprecated. Also, it doesn't fit in this context as there's no MySQL link.
__________________
steamID converter with OpenSearch browser plugin
8088 is offline
ILUSION
Senior Member
Join Date: Oct 2006
Location: Argentina
Old 08-26-2009 , 19:34   Re: [PHP] replace quotes
Reply With Quote #8

Try...
$whatever = str_replace("\"","\"\\", $whatever);
$whatever = stripslashes($whatever);

Last edited by ILUSION; 08-27-2009 at 12:29.
ILUSION is offline
[ --<-@ ] Black Rose
ANNIHILATED
Join Date: Sep 2005
Location: Stockholm, Sweden.
Old 08-27-2009 , 01:49   Re: [PHP] replace quotes
Reply With Quote #9

I didn't realize you had to use the returned string. I thought the input one would be replaced.

This works:
PHP Code:
$contents str_replace('"''\\"'$contents);
$contents str_replace("'""\\'"$contents); 
[ --<-@ ] Black Rose is offline
cs1.7
Senior Member
Join Date: Oct 2008
Old 08-28-2009 , 05:31   Re: [PHP] replace quotes
Reply With Quote #10

[ --<-@ ] Black Rose


nice to see you are back.
cs1.7 is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 07:25.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode