How do I insert a backslash every time there is an apostroph

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Antek_Ryu
Forum Commoner
Posts: 34
Joined: Tue Aug 09, 2005 10:55 am

How do I insert a backslash every time there is an apostroph

Post by Antek_Ryu »

Hi All

I am trying to put in a backslash everytime I recieve text from a form that has apostraphies. I recieve this text that goes into the database and then my webpage displays the text. The webpage that displays the text uses javascript and the javascript will only accept apostrophies if it is backslashed. I have used the following


addbackslash();

but it doesnt do anything






Regards
Antek
Grim...
DevNet Resident
Posts: 1445
Joined: Tue May 18, 2004 5:32 am
Location: London, UK

Post by Grim... »

addslashes()

To get rid of the backslashes again, use stripslashes()
Antek_Ryu
Forum Commoner
Posts: 34
Joined: Tue Aug 09, 2005 10:55 am

Post by Antek_Ryu »

Sorry I meant i put in addslashes() but it doesent put in slashes!
Antek_Ryu
Forum Commoner
Posts: 34
Joined: Tue Aug 09, 2005 10:55 am

Post by Antek_Ryu »

Actually it does put in a slash for (") I want it to put in a slash for ('). How can I make it do that, thanks.
foobar
Forum Regular
Posts: 613
Joined: Wed Sep 28, 2005 10:08 am

Post by foobar »

Code: Select all

$text = addcslashes($text, $charlist);
All chars in $charlist will be escaped in $text.
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

If using mysql, use mysql_real_escape_string()
Post Reply