LanceT Posted January 13, 2008 Share Posted January 13, 2008 If my user inputs quotes and apostrophes into fields, the form messes up, however, I WANT them to be able to input both quotes and apostrophes. What is the code to replace quotes and apostrophes? I can't quite remember. Sorry. Quote Link to comment https://forums.phpfreaks.com/topic/85782-replacing-quotes-and-apostrophes/ Share on other sites More sharing options...
phpQuestioner Posted January 13, 2008 Share Posted January 13, 2008 you can use addslashes: http://us2.php.net/manual/en/function.addslashes.php Quote Link to comment https://forums.phpfreaks.com/topic/85782-replacing-quotes-and-apostrophes/#findComment-437823 Share on other sites More sharing options...
twostars Posted January 13, 2008 Share Posted January 13, 2008 If my user inputs quotes and apostrophes into fields, the form messes up, however, I WANT them to be able to input both quotes and apostrophes. What is the code to replace quotes and apostrophes? I can't quite remember. Sorry. Occasionally I forget about addslashes and use this: <?php # Input echo "Original message: {$_POST['message']}<br />"; $message = str_replace("'", "`*+", $_POST['message']); # Where the second parameter is a string that is unlikely to be used at all. $message = str_replace('"', "#%&", $message); echo "After input conversion: {$message}"; # Output $message = str_replace("`*+", "'", $_POST['message']); # Where the second parameter is a string that is unlikely to be used at all. $message = str_replace("#%&", '"', $message); echo "After conversion back to output: {$message}"; ?> Of course, its very tedious to remember but eh.. it works. Quote Link to comment https://forums.phpfreaks.com/topic/85782-replacing-quotes-and-apostrophes/#findComment-437827 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.