gotornot Posted October 30, 2010 Share Posted October 30, 2010 Hi What code would i use to take the first 2 letters of a post code so for example CM11 2AY I want the CM bit what command would strip the first 2 characters out? Thanks Link to comment https://forums.phpfreaks.com/topic/217307-get-just-2-characters/ Share on other sites More sharing options...
Pikachu2000 Posted October 30, 2010 Share Posted October 30, 2010 substr() Link to comment https://forums.phpfreaks.com/topic/217307-get-just-2-characters/#findComment-1128423 Share on other sites More sharing options...
PaulRyan Posted October 30, 2010 Share Posted October 30, 2010 <?PHP $postcode = 'CM11 2AY'; $postcode = substr($postcode, 0, 2); echo $postcode; ?> Regards, Paul. Link to comment https://forums.phpfreaks.com/topic/217307-get-just-2-characters/#findComment-1128424 Share on other sites More sharing options...
gotornot Posted October 30, 2010 Author Share Posted October 30, 2010 thanks very much people i worked it out in the end but really good thanks. Whatis the best command for srtipping out the numbers if any are included? Link to comment https://forums.phpfreaks.com/topic/217307-get-just-2-characters/#findComment-1128427 Share on other sites More sharing options...
Pikachu2000 Posted October 30, 2010 Share Posted October 30, 2010 This would remove any numeric characters. <?php $string = '1 4m l337 h4x0r'; $search = range(0,9); $replace = ''; $new = str_replace($search, $replace, $string); echo $new; ?> Link to comment https://forums.phpfreaks.com/topic/217307-get-just-2-characters/#findComment-1128430 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.