brown2005 Posted September 24, 2007 Share Posted September 24, 2007 hi if i have $word = cabbages_green is there a way i can get $word 1 = cabbages $word 2 = green thanks Quote Link to comment https://forums.phpfreaks.com/topic/70439-splitting-a-word-with-_-in-the-middle/ Share on other sites More sharing options...
hellouthere Posted September 24, 2007 Share Posted September 24, 2007 $word = "cabbages_green"; $newword = explode("_", $word); $newword[0] = cabbages $newword[1] = green Quote Link to comment https://forums.phpfreaks.com/topic/70439-splitting-a-word-with-_-in-the-middle/#findComment-353852 Share on other sites More sharing options...
HuggieBear Posted September 24, 2007 Share Posted September 24, 2007 I find using list() normally more appropriate for just splitting once... <?php $word = 'cabbages_green'; // Now assign the word parts to new variables list($veg, $colour) = explode('|', $word); ?> Regards Huggie Quote Link to comment https://forums.phpfreaks.com/topic/70439-splitting-a-word-with-_-in-the-middle/#findComment-353863 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.