jagguy Posted March 24, 2007 Share Posted March 24, 2007 Hi, I am recieving a POST variable with numbers seperated by underscores in this format eg 2_19 or 1_2_12 etc of variable length but usually no more than a few underscores between each number. How can i extract the numbers from this string as I have looked at substr but this requires knowing the exact length of the numbers. If i don't know the size and numbers before hand what can i do to get the numbers seperated by underscore on their own? Link to comment https://forums.phpfreaks.com/topic/44100-string-split/ Share on other sites More sharing options...
fert Posted March 24, 2007 Share Posted March 24, 2007 $nums=explode("_",$numbers); print_r($nums); Link to comment https://forums.phpfreaks.com/topic/44100-string-split/#findComment-214118 Share on other sites More sharing options...
jitesh Posted March 24, 2007 Share Posted March 24, 2007 Perfect idea by fert Link to comment https://forums.phpfreaks.com/topic/44100-string-split/#findComment-214140 Share on other sites More sharing options...
jagguy Posted March 24, 2007 Author Share Posted March 24, 2007 Hi, Tkanks for that answer. how do you remove the last number and '_' from the same list? I can do it a long way but is their an easy way. eg 1_19_65 to 1_19 Link to comment https://forums.phpfreaks.com/topic/44100-string-split/#findComment-214156 Share on other sites More sharing options...
Orio Posted March 24, 2007 Share Posted March 24, 2007 <?php $nums = explode("_",$numbers); unset($nums[count($nums)-1]); print_r($nums); ?> Orio. Link to comment https://forums.phpfreaks.com/topic/44100-string-split/#findComment-214197 Share on other sites More sharing options...
Orio Posted March 24, 2007 Share Posted March 24, 2007 Or this way... Using array_pop() <?php $nums = explode("_",$numbers); array_pop($nums); print_r($nums); ?> Orio. Link to comment https://forums.phpfreaks.com/topic/44100-string-split/#findComment-214199 Share on other sites More sharing options...
jagguy Posted March 24, 2007 Author Share Posted March 24, 2007 thanks Link to comment https://forums.phpfreaks.com/topic/44100-string-split/#findComment-214512 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.