Hi I'm trying to code a search module that has one input text box, which then searches a database. In the text box the user is asked to enter a town or a uk postcode.
Some PHP help please
9
Hi
I'm trying to code a search module that has one input text box, which then searches a database. In the text box the user is asked to enter a town or a uk postcode.
The database does not contain full postcodes, it contains post codes like BD23 1 (the postcode area). My search works fine if I enter a town, or a postcode as it is in the database, but not if I enter a full postcode (BD23 1AA). I need to strip off the AA (last two characters if they are non numeric.
I have this code:
It does not strip off the last two characters. Would really appreciate if a php guru could help with this, as my PHP isn't that great.
Thanks in advance.
I'm trying to code a search module that has one input text box, which then searches a database. In the text box the user is asked to enter a town or a uk postcode.
The database does not contain full postcodes, it contains post codes like BD23 1 (the postcode area). My search works fine if I enter a town, or a postcode as it is in the database, but not if I enter a full postcode (BD23 1AA). I need to strip off the AA (last two characters if they are non numeric.
I have this code:
Code:
/*IF THERES A DIGIT IN KEYWORD ASSUME POSTCODE*/
if (preg_match('/[^0-9A-Za-z]+$/',$keyword)) {
//SEE IF LAST 2 CHARS ARE LETTERS
$last3chars = substr($keyword, -2);
if (!is_int(substr($last3chars, -2))) {
$keyword = substr($keyword,0,-2);
}
} Thanks in advance.
- FirstSocialApps
- [1] reply
- timmykins
- festi9
- [1] reply
- timmykins
- [1] reply
Next Topics on Trending Feed
-
9