refiking Posted December 12, 2008 Share Posted December 12, 2008 I have a string that has 5 values separated by a dash. How can I break this into 5 variables? //string example $result = one-two-three-four-five $part1 = 'one'; $part2 = 'two'; $part3 = 'three'; $part4 = 'four'; $part5 = 'five'; Link to comment https://forums.phpfreaks.com/topic/136704-solved-how-to-separate-string/ Share on other sites More sharing options...
gevans Posted December 12, 2008 Share Posted December 12, 2008 $anArray = explode("-",$result); Link to comment https://forums.phpfreaks.com/topic/136704-solved-how-to-separate-string/#findComment-713854 Share on other sites More sharing options...
mmarif4u Posted December 12, 2008 Share Posted December 12, 2008 By explode function Or split. $result = "one-two-three-four-five"; $result = explode("-",$result); $result[0]; /will print one $result[1]; /will print two $result[2]; /will print three $result[3]; /will print four $result[4]; /will print five hope this helps. Link to comment https://forums.phpfreaks.com/topic/136704-solved-how-to-separate-string/#findComment-713857 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.