Jump to content

[SOLVED] removing quotes from text field input


kcp4911

Recommended Posts

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

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);
    }
}
?>

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.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.