Re: searching by _'s problem :(

From: Date: Mon, 04 Dec 2000 14:23:39 +0000
Subject: Re: searching by _'s problem :(
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-28578@lists.php.net to get a copy of this message
>>>>> "SH" == Sandeep Hundal <sandeep_wde@yahoo.com> writes: > Problem - the first bit doesnt work, and $srch still has a space in > between :( Also, english postcodes are like: AA1 5AA . Even if i > convert it to "AA15AA", what I need to do is put 3d and 4th letters > as wildcards ("_" in sql i hear). But how can I if its a variable > ??? :(( > Any help would be nice!! Hiyah, I can't really help you with the MySQL, but I could possibly save you some grief with the postcodes. The problem with UK postcodes (as I see it anyway) is that the're not consistent. Some, as you said are in the form 'AA1 1AA', but 'A1 1AA', 'AA11 1AA', 'A11 1AA', 'A1A 1AA' and 'AA1A 1AA' are all valid syntaxes too. All this means is that you can't just replace the third and fourth letters with wildcards, you have to be slightly more selective. I wrote this function to help parse postcodes which might be some use. It returns a hash of the parts which you can stick together with any wildcards for your search. <?php function valid_uk_postcode($candidate) { // UK postcodes consist of two parts known as the outward part and the inward part. // Each part consists of two sections: // The outward part consists of: // A one or two letter string called the 'area' followed by; // A single digit followed by a digit (or letter in, known as the 'district'. // The inward part consists of: // A single digit known as the 'sector' followed by; // A two letter string called the 'walk'. // // Examples: // W3 0RG, EX16 9RH, W16 1AB, S1E 3FG, EX1 1AA if (ereg('^([A-Z]{1,2})([0-9][0-9A-Z]?)[[:space:]]*([0-9])([A-Z]{2})$', strtoupper(trim($candidate)), $postcode)) { return array( 'AREA' => $postcode[1], 'DISTRICT' => $postcode[2], 'SECTOR' => $postcode[3], 'WALK' => $postcode[4], 'OUTWARD' => $postcode[1] . $postcode[2], 'INWARD' => $postcode[3] . $postcode[4] ); } return false; } ?> -- Robin Vickery............................................... Planet-Three, 3A West Point, Warple Way, London, W3 0RG, UK Email: robin@planet-three.net Phone: +44 (0)870 729 5444

« previous php.general (#28578) next »