Help: Tagging from keyword list?

Discussion in 'PHP' started by prometheus, Sep 18, 2007.

Thread Status:
Not open for further replies.
  1. #1
    Hi,
    i need to help, i have a keywords field in database.
    There are keywords that are seperated with commas like "cat, dog, fat, dude"
    ı want to convert these to
    Tags: <a href="cat">cat</a>, <a href="dog">dog</a>, <a href="fat">fat</a>, <a href="dude">dude</a>
    how can i success this as a function?
    thanks.
     
    prometheus, Sep 18, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    
    $string = preg_replace('/[^\,\s]+/', '<a href="$0">$0</a>', $string);
    
    PHP:
     
    nico_swd, Sep 18, 2007 IP
  3. prometheus

    prometheus Banned

    Messages:
    880
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thanks for your help,
    i want to use trim() function in the second parameter like;
    
    $string = preg_replace('/[^\,\s]+/', '<a href="$0">trim("$0")</a>', $string);
    
    PHP:
    But i doesnt work, what is the wrong?
     
    prometheus, Sep 18, 2007 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #4
    With my code, there won't be any spaces in the <a> tags. Maybe there'll be spaces outside them, but they're only visible in the source code (if more than one) Is that a problem?
     
    nico_swd, Sep 18, 2007 IP
  5. prometheus

    prometheus Banned

    Messages:
    880
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    0
    #5
    i have used trim() just for an example, i will use many functions.
    so should i use e modifier?
     
    prometheus, Sep 18, 2007 IP
  6. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #6
    No, the e modifier.
    
    $string = preg_replace('/[^\,\s]+/e', '"<a href=\"$0\">" . trim("$0")  ."</a>"', $string);
    
    PHP:
     
    nico_swd, Sep 18, 2007 IP
    prometheus likes this.
  7. prometheus

    prometheus Banned

    Messages:
    880
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    0
    #7
    great!, it is working, gave you a reputation.
    thanks alot.
     
    prometheus, Sep 18, 2007 IP
  8. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #8
    And sorry, I meant to say "yes, the e modifier", lol. I read your message too fast and thought you said "should I use the i modifier". :p

    Glad you got it working though.
     
    nico_swd, Sep 18, 2007 IP
Thread Status:
Not open for further replies.