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 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! 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]; ?> 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}; ?> 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 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. 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 Link to comment https://forums.phpfreaks.com/topic/53646-strip-a-number/#findComment-265182 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.