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? Quote Link to comment Share on other sites More sharing options...
fert Posted March 24, 2007 Share Posted March 24, 2007 $nums=explode("_",$numbers); print_r($nums); Quote Link to comment Share on other sites More sharing options...
jitesh Posted March 24, 2007 Share Posted March 24, 2007 Perfect idea by fert Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
jagguy Posted March 24, 2007 Author Share Posted March 24, 2007 thanks Quote Link to comment 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.