spacepoet Posted March 14, 2012 Share Posted March 14, 2012 Hello: I have a quick question. I am currently using the following code to replace an apostrophe and quote marks when inserting and updating a database record: $myPageContent = mysql_real_escape_string(str_replace("'", "'", $_POST['myPageContent'])); $myPageContent = mysql_real_escape_string(str_replace("", """, $_POST['myPageContent'])); My question is - how can I modify it so I only need to use one line. Like (but this does not work): $myPageContent = mysql_real_escape_string(str_replace("'", "'", "", """, $_POST['myPageContent'])); It seems to me that the way I am currently doing it might be POSTing the data twice? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/258935-using-a-replace-only-once/ Share on other sites More sharing options...
scootstah Posted March 14, 2012 Share Posted March 14, 2012 The first replace will essentially be ignored in your first code, because you aren't actually modifying the $_POST value. You can use arrays in str_replace to replace multiple values. $myPageContent = mysql_real_escape_string(str_replace(array('\'', '"'), array(''', '"'), $_POST['myPageContent'])); Quote Link to comment https://forums.phpfreaks.com/topic/258935-using-a-replace-only-once/#findComment-1327427 Share on other sites More sharing options...
spacepoet Posted March 15, 2012 Author Share Posted March 15, 2012 Excellent! Works like a charm. Thanks for the tip! Quote Link to comment https://forums.phpfreaks.com/topic/258935-using-a-replace-only-once/#findComment-1327519 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.