mcmuney Posted September 27, 2007 Share Posted September 27, 2007 How do I pull a specified number of characters either from the right or left? For example, the output is 123456 and I want to pull, separately, the right 3 characters (result: 456) and the left 2 characters (result: 12). Link to comment https://forums.phpfreaks.com/topic/70965-solved-pulling-rightleft-characters/ Share on other sites More sharing options...
trq Posted September 27, 2007 Share Posted September 27, 2007 substr(). Link to comment https://forums.phpfreaks.com/topic/70965-solved-pulling-rightleft-characters/#findComment-356770 Share on other sites More sharing options...
effigy Posted September 28, 2007 Share Posted September 28, 2007 ...or all at once: <pre> <?php $nums = array( 1234, 12345, 123456, 1234567, 12345678, 123456789 ); foreach ($nums as $num) { preg_match('/\A(\d{2}).*(\d{3})\z/', $num, $matches); print_r($matches); } ?> </pre> Link to comment https://forums.phpfreaks.com/topic/70965-solved-pulling-rightleft-characters/#findComment-357174 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.