coderb Posted January 3, 2008 Share Posted January 3, 2008 Hi, Can someone please tell me how to handle a string value containing a single quote when used in dynamically built html. I have a form that posts back to itself. An input text field which first gets it's value from the database, containing string : haven't this string is displayed correctly the first time, but when I post back the page to itself and repopulate the input text string with its $_POST value, the displayed string is now : haven\'t why is the backslash inserted before the quote? how should I handle this? thanks, Quote Link to comment https://forums.phpfreaks.com/topic/84286-solved-handling-single-quotes-within-variable/ Share on other sites More sharing options...
Daukan Posted January 3, 2008 Share Posted January 3, 2008 Use htmlentities on the text before sending it to the form. see htmlentities Quote Link to comment https://forums.phpfreaks.com/topic/84286-solved-handling-single-quotes-within-variable/#findComment-429239 Share on other sites More sharing options...
Gamic Posted January 3, 2008 Share Posted January 3, 2008 Have a look at this article on magic quotes. It should answer all of your questions. Quote Link to comment https://forums.phpfreaks.com/topic/84286-solved-handling-single-quotes-within-variable/#findComment-429243 Share on other sites More sharing options...
coderb Posted January 3, 2008 Author Share Posted January 3, 2008 thanks for the quick responses. initially tried the htmlentities, but didn't do the trick, I think the Magic Quotes seems to be reason. however, the the Magic Quotes link you inlcuded mentions a Warning - This feature is DEPRECATED and REMOVED as of PHP 6.0.0. Relying on this feature is highly discouraged. So with this in mind should I just switch off magic_quotes_gpc or still use the stripslashes function? Quote Link to comment https://forums.phpfreaks.com/topic/84286-solved-handling-single-quotes-within-variable/#findComment-429261 Share on other sites More sharing options...
rajivgonsalves Posted January 3, 2008 Share Posted January 3, 2008 use stripslashes on you variables http://php.net/stripslashes Quote Link to comment https://forums.phpfreaks.com/topic/84286-solved-handling-single-quotes-within-variable/#findComment-429262 Share on other sites More sharing options...
coderb Posted January 3, 2008 Author Share Posted January 3, 2008 thanks forthe help, that did the trick. Quote Link to comment https://forums.phpfreaks.com/topic/84286-solved-handling-single-quotes-within-variable/#findComment-429282 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.