simon551 Posted January 26, 2009 Share Posted January 26, 2009 I'm having a difficult time with this code. I have a form with a text box that the user can enter in anything they want. They use special characters and I'm not adept at handling that. this is the code that gets me in trouble: $specialR=$_POST['specialRequests']; $_SESSION['specialRequests']=$specialR; $_SESSION['specialRequests'] = str_replace("&", "&", $_SESSION['specialRequests']); $_SESSION['specialRequests'] = str_replace("<", "-", $_SESSION['specialRequests']); $_SESSION['specialRequests'] = str_replace(">", "-", $_SESSION['specialRequests']); $_SESSION['specialRequests'] = str_replace("'", "´", $_SESSION['specialRequests']); $_SESSION['specialRequests'] = str_replace("/", "", $_SESSION['specialRequests']); If I submit "Don't Print" in the form field specialRequests and then echo back $_SESSION['specialRequests] I get "Don\'t Print" when I just want to see "Don't Print". Do you know a way around this? I tried putting in str_replace for $_SESSION['specialRequests'] = str_replace("\", "", $_SESSION['specialRequests']); but that doesn't work because of the special character \. Argh. Quote Link to comment https://forums.phpfreaks.com/topic/142519-solved-str_replace/ Share on other sites More sharing options...
Maq Posted January 26, 2009 Share Posted January 26, 2009 You have to escape it "\\". Quote Link to comment https://forums.phpfreaks.com/topic/142519-solved-str_replace/#findComment-746828 Share on other sites More sharing options...
rhodesa Posted January 26, 2009 Share Posted January 26, 2009 can you please run the following code and post the output: print get_magic_quotes_gpc() ? "I've been a bad boy and magic quotes are enabled" : "I'm awesome and magic quotes are disabled"; Quote Link to comment https://forums.phpfreaks.com/topic/142519-solved-str_replace/#findComment-746830 Share on other sites More sharing options...
simon551 Posted January 26, 2009 Author Share Posted January 26, 2009 I've been a bad boy and magic quotes are enabled what now? Quote Link to comment https://forums.phpfreaks.com/topic/142519-solved-str_replace/#findComment-746834 Share on other sites More sharing options...
gevans Posted January 26, 2009 Share Posted January 26, 2009 can you please run the following code and post the output: print get_magic_quotes_gpc() ? "I've been a bad boy and magic quotes are enabled" : "I'm awesome and magic quotes are disabled"; hahaha, love it Quote Link to comment https://forums.phpfreaks.com/topic/142519-solved-str_replace/#findComment-746836 Share on other sites More sharing options...
rhodesa Posted January 26, 2009 Share Posted January 26, 2009 I've been a bad boy and magic quotes are enabled what now? I highly recommend disabling magic quotes (Example 1 in link). If you can't, disable them at runtime (Example 2 in link) http://us2.php.net/manual/en/security.magicquotes.disabling.php Quote Link to comment https://forums.phpfreaks.com/topic/142519-solved-str_replace/#findComment-746850 Share on other sites More sharing options...
simon551 Posted January 26, 2009 Author Share Posted January 26, 2009 Thanks. That worked. I'll look more into magic quotes. I don't want to turn them off for the whole site just yet, but I turned them off in the page and that took care of the problem. Quote Link to comment https://forums.phpfreaks.com/topic/142519-solved-str_replace/#findComment-746876 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.