Results 1 to 4 of 4

Thread: How do you strip quotes out of POST data?

  1. #1
    Join Date
    Sep 2007
    Location
    Maui
    Posts
    602
    Thanks
    266
    Thanked 13 Times in 13 Posts

    Default How do you strip quotes out of POST data?

    I have an events calendar where people submit their own events. I have fields for meta description and meta keywords. People are entering double quotes into the fields which is messing things up.

    How do you strip quotes out of the data before loading to the database? I already do this: $meta_keyword = mysql_real_escape_string($_POST['meta_keyword']); , but it doesn't help.

    Thanks!

  2. #2
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 517 Times in 503 Posts
    Blog Entries
    5

    Default

    Is this a database problem, or are quotes simply not allowed for the type of information you're collecting? (Since you say "meta description," I'll assume this is for an HTML meta tag, where quotes would mess up the HTML output.)

    Use str_replace:
    PHP Code:
    <?php
    $quotes 
    'I just wanted to say "Hello!"';

    # three arguments:
    #    1) the string to search for, in this case, " (double-quotes)
    #    2) the string to replace with, in this case, nothing (an empty string)
    #    3) the subject string
    $noQuotes str_replace'"','',$quotes );

    print 
    $noQuotes;
    /* prints
     I just wanted to say Hello!
    */
    If this is indeed for a meta tag, you'd probably want to strip out single-quotes as well:
    PHP Code:
    str_replace( array( "'","'" ),'',$quotes );
    # note, that's "'" (a single quote, in a double-quoted string) and '"' (a double-quote, in a single-quoted string). 

  3. The Following User Says Thank You to traq For This Useful Post:

    kuau (10-02-2013)

  4. #3
    Join Date
    Sep 2007
    Location
    Maui
    Posts
    602
    Thanks
    266
    Thanked 13 Times in 13 Posts

    Default

    Dear Adrian: Brilliant! That solved the one problem, which made it obvious that that was not the source of the problem. So then I was able to figure out that problem. So you actually solved 2 problems at once. Mahalo! aa

  5. #4
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 517 Times in 503 Posts
    Blog Entries
    5

Similar Threads

  1. Proper Use of Quotes with POST?
    By kuau in forum PHP
    Replies: 14
    Last Post: 06-04-2008, 06:19 PM
  2. CARTOON STRIP...need help!!
    By sushi2hot4u in forum Java
    Replies: 0
    Last Post: 03-17-2008, 08:55 AM
  3. single quotes & double quotes insert into mysql
    By shyne in forum MySQL and other databases
    Replies: 3
    Last Post: 11-25-2007, 08:18 PM
  4. Replies: 2
    Last Post: 07-06-2006, 07:11 PM
  5. Strip Characters
    By NXArmada in forum PHP
    Replies: 20
    Last Post: 04-28-2006, 03:28 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •