Go Back  HTML Forums - Free Webmaster Forums and Help Forums > WEBSITE DEVELOPMENT > Server Side Programming > PHP Programming
User Name:
Password:
 

Reply
Thread Tools   Display Modes
  View First Unread
 
Old 11-05-2009, 11:34 AM
  #1
tom_haire50
Novice (Level 1)
 
Join Date: Nov 2009
Posts: 6
iTrader: (0)
tom_haire50 is an unknown quantity at this point
PHP Postcode Search

I have created a website with a postcode search, all the postcodes are stored in a text file. The php searches through text file to see if a postcode typed in by the user is in the text file.

I have set it up so that it only reads the first part of the postcode e.g. YO12 4AA is typed in the php with search the text file for YO12, it reads up to the space.

If someone types in YO124AA (without a space) it searches the whole postcode, which is not contained in the file. My code is below i cant think of a better solution without using a database
PHP Code:
<?php 
$handle 
file_get_contents("Postcodes.txt",NULL); 
$submit=$_POST['Submit'];
$a =$_POST['Postcode'];
$a=str_replace(",","",$a); 
$a=explode(" ",$a);
$postcode reset(explode(' '$postcode));
$c=0
foreach(
$a as $y){ 
if (
stristr($handle,"$a[$c]")) $b[]= 'yes'
else 
$b[]='no'
$c++; 
}

if (
in_array("yes",$b)) header("Refresh: 0; url=inYourArea.html?i=idx");
                        

else 
header("Refresh: 0; url=notInYourArea.html?i=idx");

?>
tom_haire50 is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 11-05-2009, 05:17 PM
  #2
Horus_Kol
Mod of the Underlay
 
Horus_Kol's Avatar
 
Join Date: Jun 2002
Location: At a desk, hooked up and ready to rock
Posts: 17,242
iTrader: (0)
Horus_Kol is a glorious beacon of lightHorus_Kol is a glorious beacon of lightHorus_Kol is a glorious beacon of lightHorus_Kol is a glorious beacon of lightHorus_Kol is a glorious beacon of light
UK postcodes?

hmm.. you could try this:

PHP Code:
$area explode(' '$_POST['postcode']);

if (
strlen($area) > 4) { // since, I believe, the area code is never more than 4 characters

  
$area substr($area, -3); // since the street part of the postcode is always 3 characters

}

// search using $area 
__________________
Personal Blog (and photos): HorusKol
Articles on Programming and Development (PHP/HTML/CSS, C/C++, more): RandomTweak

The great secret that no SEO agent wants you to hear: if you build your website using w3c accessibility guidelines and your content is written for people, you will do better for longer in search engines than any other method...
Horus_Kol is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 11-06-2009, 05:16 AM
  #3
tom_haire50
Novice (Level 1)
 
Join Date: Nov 2009
Posts: 6
iTrader: (0)
tom_haire50 is an unknown quantity at this point
Yeah, I never thought of that! In theory it should work alright. I will change it over now and see how it goes.
tom_haire50 is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 11-06-2009, 10:38 AM
  #4
tom_haire50
Novice (Level 1)
 
Join Date: Nov 2009
Posts: 6
iTrader: (0)
tom_haire50 is an unknown quantity at this point
Works Great. Cheers

Last edited by tom_haire50 : 11-09-2009 at 10:52 AM.
tom_haire50 is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote

Reply
KEEP TABS
SPONSORS
 
Boxedart
 
 


 
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
  
 
 
 



 
  POSTING RULES
 
 
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Thread Tools
Display Modes

Forum Jump

 

All times are GMT -5. The time now is 04:19 AM.

   

Mascot team created by Drawshop.com

Powered by vBulletin® Version 3.6.7
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.

Server Monitoring by ENIACmonitor 0.01
HTMLforums.com © Big Resources, Inc. Web Design by BoxedArt.com
vRewrite 1.5 beta SEOed URLs completed by Tech Help Forum and Chalo Na.