How do I do this with PHP?
Is it just $text = str_replace("'","\'", $text); ?
Many thanks for any help.
| SitePoint Sponsor |





How do I do this with PHP?
Is it just $text = str_replace("'","\'", $text); ?
Many thanks for any help.

Have you tried it?
It works on my php.
Wouldn't the native addslashes and stripslashes be more appropriate?
PHP Code:<?php
$sString = addslashes("'''''''");
echo $sString; #\'\'\'\'\'\'\'
$sString = stripslashes($sString);
echo $sString; #'''''''
?>
@AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.





Aaaah. Thanks guys.
Basically I'm using the TinyMCE editor to insert text in <textarea>'s and if my text was:
Hi, I'm Michael
then it would still try to enter Hi, I'm Michael into the db, rather than making it Hi, I\'m Michael.
So should I try $descr = addslashes($descr); to fix this ?
I'm escaping all my data and it works great, except those using the TinyMCE editor.





Heh, my first one did work. How about that
Yep, it definitely works. I'm chuffed.
I've got a few questions I might try to get answered in the next few days, to get my head around slashes and such.
Bookmarks