Jump to content

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.

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.