formatting meta keywords into text

Discussion in 'PHP' started by mnymkr, Sep 24, 2007.

  1. #1
    I am working a little project

    I need to take the keyword entered by my users and present them somewhere else.

    however since my users enter the keywords on their own they are sometimes in different formats

    for example,

    one might have

    big red cowboys

    two might have

    big, red, cowboys

    three may have

    "big red" cowboys

    etc

    what i need to do is take what they have no matter what and convert it to

    big; red; cowboys

    is this possible?
     
    mnymkr, Sep 24, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    
    $keywords = implode('; ', preg_split('/[^\w-]+/', $string, -1, 1));
    
    echo $keywords;
    
    PHP:
     
    nico_swd, Sep 24, 2007 IP
  3. mnymkr

    mnymkr Well-Known Member

    Messages:
    2,328
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    120
    #3
    hey thanks. i took your advice on a specific question. and i read about preg_split but to be honest i really don't get most of the preg functions
     
    mnymkr, Sep 24, 2007 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #4
    I'd suggest leaning the other stuff first. Learn more about the basics and things you need more often at the beginning.

    And there's a very recent topic about learning Regular expressions in the PHP section, have a look at it when you think you're ready.
     
    nico_swd, Sep 25, 2007 IP
  5. mnymkr

    mnymkr Well-Known Member

    Messages:
    2,328
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    120
    #5
    is it possible when doing the above to keep key phrases together

    "big red", cowboys, hat

    to

    big red; cowboys; hat;
     
    mnymkr, Sep 29, 2007 IP