each word new link

Discussion in 'PHP' started by zodiac, Dec 26, 2009.

  1. #1
    in the database field:
    s:11:"word1,word2";
    <?
    			$row['keywords'] = unserialize($row['keywords']);
    			$row['keywords'] = str_replace(',',' ',$row['keywords']);
    			?>
    			<?=$row['keywords'];?>
    PHP:
    prints:
    word1 word2
    Code (markup):
    i want to echo each word into a link:
    echo '<a href="http://www.domain.com/search.php?q='.$row[keywords].'"</a>';
    PHP:
    so it's like:
    word1 word2
     
    zodiac, Dec 26, 2009 IP
  2. CodedCaffeine

    CodedCaffeine Peon

    Messages:
    130
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    <?php
    /***********************
    * Keyword Listing
    ************************
    * Written by Joel Larson (Coded Caffeine)
    *   Author URL: http://thejoellarson.com/
    *   Date: 26.12.09
    ***********************/
    
    # $row['keywords'] = serialized array from DB
    
    # Unserialize the array.
    $row['keywords'] = unserialize($row['keywords']);
    
    # Seperate each keyword into an array variable.
    $row['keywords'] = explode(',', $row['keywords']);
    
    # For each keyword that exists..
    foreach($row['keywords'] as $keyword)
    {
    	# Echo the proper html.
    	echo '<a href="http://www.domain.com/search.php?q=',$keyword,'"</a>';
    }
    
    /* END OF FILE */
    PHP:
     
    CodedCaffeine, Dec 26, 2009 IP
    zodiac likes this.
  3. zodiac

    zodiac Peon

    Messages:
    2,661
    Likes Received:
    82
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thanks,had almost all of that,but it now works with the explode. :)
     
    zodiac, Dec 26, 2009 IP