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 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 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 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
Archived
This topic is now archived and is closed to further replies.