komquat Posted May 30, 2007 Share Posted May 30, 2007 I AM getting 111111 as a variable, I want the first 1 of that series. I can not get it to work with substr(), is there anything else I can do? Thank you Quote Link to comment https://forums.phpfreaks.com/topic/53646-strip-a-number/ Share on other sites More sharing options...
MadTechie Posted May 30, 2007 Share Posted May 30, 2007 substr() not working ? show some code please can you show what you expect the output to be as i think you mean 111111 to 1 being the first number. but i am not sure! Quote Link to comment https://forums.phpfreaks.com/topic/53646-strip-a-number/#findComment-265175 Share on other sites More sharing options...
per1os Posted May 30, 2007 Share Posted May 30, 2007 <?php $value = '111111'; $firstVal = substr($value, 0); ?> That does not work? If not this should work <?php $value = '111111'; $firstVal = $value[0]; ?> Quote Link to comment https://forums.phpfreaks.com/topic/53646-strip-a-number/#findComment-265176 Share on other sites More sharing options...
MadTechie Posted May 30, 2007 Share Posted May 30, 2007 correction <?php $value = '111111'; $firstVal = $value{0}; ?> Quote Link to comment https://forums.phpfreaks.com/topic/53646-strip-a-number/#findComment-265178 Share on other sites More sharing options...
tommyboy123x Posted May 30, 2007 Share Posted May 30, 2007 $string = str_split($string) --- php 5 only echo $string[0]; explode('', $string); echo $string[0]; those two should work... they do for me at least Quote Link to comment https://forums.phpfreaks.com/topic/53646-strip-a-number/#findComment-265179 Share on other sites More sharing options...
per1os Posted May 30, 2007 Share Posted May 30, 2007 $string = str_split($string) --- php 5 only echo $string[0]; explode('', $string); echo $string[0]; those two should work... they do for me at least I think you are making it too complicated. Strings are already an array of characters, you do not need to do any exploding or splitting. Simply calling $string[0] will pull the first character out of the string without any extra lines or coding involved. Quote Link to comment https://forums.phpfreaks.com/topic/53646-strip-a-number/#findComment-265181 Share on other sites More sharing options...
tommyboy123x Posted May 30, 2007 Share Posted May 30, 2007 probly, but it IS an alternative Quote Link to comment https://forums.phpfreaks.com/topic/53646-strip-a-number/#findComment-265182 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.