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 Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted October 30, 2010 Share Posted October 30, 2010 substr() Quote Link to comment 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. Quote Link to comment 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? Quote Link to comment 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; ?> Quote Link to comment 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.