defroster Posted August 26, 2010 Share Posted August 26, 2010 Hello, If I have this string: $tags="baseball glove face" (this can vary from 1 to 15 different words) how would i loop through and divide these into different $tag1=baseball $tag2=glove $tag3=face .. and so on (if more words) Thanks for help Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted August 26, 2010 Share Posted August 26, 2010 Better using an array: $tags = "baseball glove face"; $tag = str_word_count($tags, 1); Quote Link to comment Share on other sites More sharing options...
defroster Posted August 26, 2010 Author Share Posted August 26, 2010 Thanks I figured it out with your help. $tags=$row['tags']; $arraytags = str_word_count($tags, 1); while (list(, $value) = each($arraytags)) { echo "<a href='search.php?q=".$value."'>".$value."</a> "; } Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted August 26, 2010 Share Posted August 26, 2010 Didn't know you wanted to know how to loop. This is shorter: $tags = $row['tags']; foreach(str_word_count($tags, 1) as $value) { echo '<a href="search.php?q="'.$value.'">'.$value.'</a>'; } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.