dcsimg
A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: PHP Search strings.

  1. #1
    Wannabe PHP Wizard
    Join Date
    Nov 2001
    Location
    Leechburg, PA
    Posts
    129

    PHP Search strings.

    Hello.

    Users imput tags into a single box. The rules are to make sure that tags are seperate by spaces. That's fine, but they also want to enter stuff like "the project" using quotes to make them one word. This still splits the string though. Any thoughts on how to merge these together? I want to accept stuff like:

    People "September 5th" Pizza Pepper "Oreo Cookies"

    This is what I got now:

    PHP Code:
    $tags  $_POST['tags'];
        
    $alltags explode(" "$tags);
        
        
    //clear out database for current image first.
        
    foreach ($alltags as $value) {
            
    $sql "
            INSERT INTO image_tags
            (`id`, `image_id`, `tag`)
            VALUES
            ('', 3, '
    $value')
            "
    ;
            
    $query mysql_query($sql) or die("Cannot query the database.<br>" mysql_error());
        } 
    It inserts into the DB fine, but the quote marks don't stay together. It looks like this:

    • People
    • "September
    • 5th"
    • Pizza
    • Pepper
    • "Oreo
    • Cookies"


    I want:

    • People
    • September 5th
    • Pizza
    • Pepper
    • Oreo Cookies
    Clinton N Godlesky
    My Stuff:
    http://www.15656.com/clint http://www.statedirt.com
    Personal Development Projects:
    http://www.15656.com/dev

  2. #2
    Registered User
    Join Date
    Feb 2001
    Posts
    13,044
    Hi,

    try this
    Code:
    <?
    $msg = "long string with \"word pairs\" and such";
    preg_match_all('/"[^"]+"|\S+/', $msg, $matches, PREG_PATTERN_ORDER);
    var_dump($matches);
    ?>
    You will need to loop over the results and remove qoutes

    Musicman

  3. #3
    Wannabe PHP Wizard
    Join Date
    Nov 2001
    Location
    Leechburg, PA
    Posts
    129
    Haven't tried it yet, but awesomeness!
    Clinton N Godlesky
    My Stuff:
    http://www.15656.com/clint http://www.statedirt.com
    Personal Development Projects:
    http://www.15656.com/dev

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center