kcp4911 Posted October 17, 2008 Share Posted October 17, 2008 Hello. I am having trouble removing double quotation marks from text from a text field input. I have no problem removing single quotes or other various strings - but double quotes are causing me all sorts of problems. For example, I have a text field named "head". Someone may input a string like - A person named "Bob" is a person. I want to remove the quotes from Bob so it looks like - A person named Bob is a person. I have tried str_replace and I have also tried converting the quotes using htmlentities() first and then using str_replace - still no luck. Here is one example that wont work... $head1 = htmlentities($_POST[head], ENT_QUOTES); $quote = array(""", "'"); $head = str_replace($quote, '', $head1); Here is another example that wont work... $head1 = htmlentities($_POST[head], ENT_QUOTES); $head = str_replace('"', '', $head1); Any ideas? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/128853-solved-removing-quotes-from-text-field-input/ Share on other sites More sharing options...
rhodesa Posted October 17, 2008 Share Posted October 17, 2008 $head = str_replace('"','',$_POST['head']); Quote Link to comment https://forums.phpfreaks.com/topic/128853-solved-removing-quotes-from-text-field-input/#findComment-667988 Share on other sites More sharing options...
hawkenterprises Posted October 17, 2008 Share Posted October 17, 2008 Have you tried preg_replace? $stripped_quotes = preg_replace("\"",'',$_POST['head']); Then entitize if need be. Quote Link to comment https://forums.phpfreaks.com/topic/128853-solved-removing-quotes-from-text-field-input/#findComment-667989 Share on other sites More sharing options...
GKWelding Posted October 17, 2008 Share Posted October 17, 2008 $head=preg_replace(""head"",$headl,$head); Where $headl if the value you want to add to the existing sentence and $head is the existing sentence.... Quote Link to comment https://forums.phpfreaks.com/topic/128853-solved-removing-quotes-from-text-field-input/#findComment-667990 Share on other sites More sharing options...
MadTechie Posted October 17, 2008 Share Posted October 17, 2008 Heres my idea.. <?php $stripped_quotes = RemoveQuotes($_POST['head']); function RemoveQuotes($string) { if(get_magic_quotes_gpc()) { return str_replace('"','',stripslashes($string)); } else { return str_replace('"','', $string); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/128853-solved-removing-quotes-from-text-field-input/#findComment-667994 Share on other sites More sharing options...
kcp4911 Posted October 17, 2008 Author Share Posted October 17, 2008 thanks for your replies but... Rhodesa - I had tried that before. It works for single quotes but not double quotes. Just to make sure I wasn't imagining things, I tried it again just then - still doesn't work. Don't worry, I know how you feel. GKWelding - I copy and pasted your code - replacing $stripped_quotes with $head - but ended up with this error when trying your suggestion... "Warning: preg_replace() [function.preg-replace]: No ending delimiter '"' found in pg3.php on line 32" Was I meant to do something else? Thanks for having a go. Quote Link to comment https://forums.phpfreaks.com/topic/128853-solved-removing-quotes-from-text-field-input/#findComment-667997 Share on other sites More sharing options...
MadTechie Posted October 17, 2008 Share Posted October 17, 2008 Have you tried my last post ? Oh an heres GKWelding example rewritten $noQuotes = preg_replace('/"(head)"/si', '\1', $_POST['head']); Quote Link to comment https://forums.phpfreaks.com/topic/128853-solved-removing-quotes-from-text-field-input/#findComment-667998 Share on other sites More sharing options...
kcp4911 Posted October 17, 2008 Author Share Posted October 17, 2008 MadTechie, you are the champion!. That did the job. Thank you very much. Now, how do I mark this thread solved? Quote Link to comment https://forums.phpfreaks.com/topic/128853-solved-removing-quotes-from-text-field-input/#findComment-667999 Share on other sites More sharing options...
MadTechie Posted October 17, 2008 Share Posted October 17, 2008 Click Solved (bottom left) i think please remember you have Magic Quotes (Now DEPRECATED) turned on.. read here Quote Link to comment https://forums.phpfreaks.com/topic/128853-solved-removing-quotes-from-text-field-input/#findComment-668001 Share on other sites More sharing options...
GKWelding Posted October 17, 2008 Share Posted October 17, 2008 my fault, try these instead... $head=preg_replace(#\"head\"#,$headl,$head); or $head=preg_replace(#"head"#,$headl,$head); Quote Link to comment https://forums.phpfreaks.com/topic/128853-solved-removing-quotes-from-text-field-input/#findComment-668002 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.