Gazan Posted March 24, 2009 Share Posted March 24, 2009 My question is very simple, however i cant seem to figure it out.. How do i explode a string and store each exploded word into an array? So the array will hold a key value for each word in the string. Thanks in advantage Quote Link to comment Share on other sites More sharing options...
Yesideez Posted March 24, 2009 Share Posted March 24, 2009 Let's use the space between words as the splitting point. $arrWords=explode(' ',$str); $str is your string and $arrWords will be your array containing the words. Quote Link to comment Share on other sites More sharing options...
Gazan Posted March 24, 2009 Author Share Posted March 24, 2009 Hmm, get what you mean, but could you provide me with an example? with, artists for example.. I'd be very thankfull if you would Quote Link to comment Share on other sites More sharing options...
Yesideez Posted March 24, 2009 Share Posted March 24, 2009 I just have. That is all the code you need. I'll break it down a little more... $arrWords=explode(' ',$str); INPUT ' ' ... This is what we're using as the split point - in this case, a space $str ... a string containing the words we want to split OUTPUT $arrWords ... an array You can output the words using a simple loop: foreach ($arrWords as $key => $word) { echo $key.' = '.$word.'<br />'; } Quote Link to comment Share on other sites More sharing options...
Gazan Posted March 24, 2009 Author Share Posted March 24, 2009 I get it now, thanks A LOT! 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.