unkwntech Posted November 27, 2008 Share Posted November 27, 2008 I have this code: $key = str_split('LMELMETETEMSGSYL75B2'); foreach($key as $i) { if(!is_integer($i)) { echo $i; } } but it is outputting: LMELMETETEMSGSYL75B2 when it should read LMELMETETEMSGSYLB The point of this is to actually preform a function on the non-integer objects the echo is just for testing Link to comment https://forums.phpfreaks.com/topic/134468-whats-going-on-with-is_integer/ Share on other sites More sharing options...
genericnumber1 Posted November 27, 2008 Share Posted November 27, 2008 You could do... <?php $key = 'LMELMETETEMSGSYL75B2'; $new = preg_replace('#[0-9]+#', '', $key); echo $new; ?> Link to comment https://forums.phpfreaks.com/topic/134468-whats-going-on-with-is_integer/#findComment-700136 Share on other sites More sharing options...
The Little Guy Posted November 27, 2008 Share Posted November 27, 2008 That is because each is being read as a string. try this: $key = str_split('LMELMETETEMSGSYL75B2'); foreach($key as $i){ $v = intval($i); if($v == 0){ echo $i; } } Link to comment https://forums.phpfreaks.com/topic/134468-whats-going-on-with-is_integer/#findComment-700140 Share on other sites More sharing options...
corbin Posted November 27, 2008 Share Posted November 27, 2008 You could also do: $key = str_split('LMELMETETEMSGSYL75B2'); foreach($key as $i) { if(!((int) $i == $i)) echo $i; } The reason is_int is returning false is because it checks the datatype, not the content. Link to comment https://forums.phpfreaks.com/topic/134468-whats-going-on-with-is_integer/#findComment-700142 Share on other sites More sharing options...
The Little Guy Posted November 27, 2008 Share Posted November 27, 2008 This works too: $key = 'LMELMETETEMSGSYL75B2'; echo preg_replace('~d~','',$key); as you can see there are many choices to choose from.. Link to comment https://forums.phpfreaks.com/topic/134468-whats-going-on-with-is_integer/#findComment-700144 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.