phoenixx Posted August 25, 2008 Share Posted August 25, 2008 I need to replace quotes and apostrophes within a string array just so that the output is compatible to insert into my database Instead of you're (for instance) it would search the string and replace all of them with you\'re or \"quoted text\". Link to comment https://forums.phpfreaks.com/topic/121275-solved-searching-and-replacing-quotes-amp-apostrophes-in-html-output/ Share on other sites More sharing options...
DarkWater Posted August 25, 2008 Share Posted August 25, 2008 Just use mysql_real_escape_string() which also cleans other problematic characters. Link to comment https://forums.phpfreaks.com/topic/121275-solved-searching-and-replacing-quotes-amp-apostrophes-in-html-output/#findComment-625211 Share on other sites More sharing options...
Mchl Posted August 25, 2008 Share Posted August 25, 2008 Assuming you use MySQL mysql_real_escape_string() or mysqli::real_escape_string() both take care of all unsafe characters. Link to comment https://forums.phpfreaks.com/topic/121275-solved-searching-and-replacing-quotes-amp-apostrophes-in-html-output/#findComment-625216 Share on other sites More sharing options...
obsidian Posted August 25, 2008 Share Posted August 25, 2008 One other note, when you pull quoted text out of the database for output, you may want to consider the htmlentities() function with the ENT_QUOTES flag set to be sure that you don't open yourself up to XSS as well. Link to comment https://forums.phpfreaks.com/topic/121275-solved-searching-and-replacing-quotes-amp-apostrophes-in-html-output/#findComment-625217 Share on other sites More sharing options...
phoenixx Posted August 25, 2008 Author Share Posted August 25, 2008 PERFECT! Here's the syntax I used for anyone who may need the same thing. Variables $foo = mysql_real_escape_string($bar); On the sql query $sql = sprintf ("INSERT INTO tablename(bar1,bar2,bar3) VALUES ('$foo1','$foo2','$foo3')") or die(mysql_error()); mysql_query ($sql); Thanks again for all of your help! Link to comment https://forums.phpfreaks.com/topic/121275-solved-searching-and-replacing-quotes-amp-apostrophes-in-html-output/#findComment-625448 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.