Hi can anyone help!
I am trying to remove the last three letters of a string ie: EC2A 1PQ becomes EC2A. but sometimes the postcode will be a different length ie: CT1 4PQ that could also be CT14PQ...So would need to be removed from right side of string.
Has anyone any ideas...
Rgds Ian
Problems emoving the last three letters of a string
Moderator: General Moderators
- icarpenter
- Forum Commoner
- Posts: 84
- Joined: Mon Mar 07, 2005 8:12 am
- Location: Kent, England
Have a look at the examples with negative offset at http://www.php.net/substr..
Regular expression wise "#\w{3}$#"
Regular expression wise "#\w{3}$#"
- harrisonad
- Forum Contributor
- Posts: 288
- Joined: Fri Oct 15, 2004 4:58 am
- Location: Philippines
- Contact:
Code: Select all
$str = "EC2A 1PQ";
$aray = explode(' ',$str);
$newstr = $aray[0];- icarpenter
- Forum Commoner
- Posts: 84
- Joined: Mon Mar 07, 2005 8:12 am
- Location: Kent, England
Thanks guys both methods worked well!!!
I used...
I used...
Code: Select all
$test = substr("EC2A 1PQ",-0,-3);
echo $test;