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 Link to comment https://forums.phpfreaks.com/topic/150862-problems-with-explode-and-array/ 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. Link to comment https://forums.phpfreaks.com/topic/150862-problems-with-explode-and-array/#findComment-792502 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 Link to comment https://forums.phpfreaks.com/topic/150862-problems-with-explode-and-array/#findComment-792504 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 />'; } Link to comment https://forums.phpfreaks.com/topic/150862-problems-with-explode-and-array/#findComment-792506 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! Link to comment https://forums.phpfreaks.com/topic/150862-problems-with-explode-and-array/#findComment-792520 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.