PHP search

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tom_haire50
Forum Newbie
Posts: 5
Joined: Mon Aug 10, 2009 11:28 am

PHP search

Post by tom_haire50 »

<? include("includes/header.php"); ?>
<?php
$handle = file_get_contents("Postcodes.txt",NULL);
$submit=$_POST['Submit'];
$a =$_POST['Postcode'];
$a=str_replace(",","",$a);
$a=explode(" ",$a);
$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=yourArea.html?i=idx");


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

?>

The above code works by checking a text file with the first part of postcodes e.g TS1, TS2. If the postcode is there it forwards one page else it forwards another. I want the user to be able to enter there full postcode e.g TS1 4AA but it only needs to check the first part. It looks more professional if the user enters there full postcode, but will still only use the first part.
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: PHP search

Post by aceconcepts »

So, what are you trying to do exactly? Give us an explanation of your objective.
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: PHP search

Post by jackpf »

You could put:

Code: Select all

$postcode = reset(explode(' ', $postcode));
Which would return only the first half of the post code.

Or, if a space isn't required,

Code: Select all

$postcode = substr($postcode, 0, 3);
tom_haire50
Forum Newbie
Posts: 5
Joined: Mon Aug 10, 2009 11:28 am

Re: PHP search

Post by tom_haire50 »

Where would I insert that code?
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: PHP search

Post by jackpf »

8O
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: PHP search

Post by jackpf »

No, you'd put it in the php script doing the processing.

Maybe you should take a look at some PHP tutorials...if you plan on having a PHP based website, I think you should at least know how it works. From what you've posted, this doesn't seem to be the case.
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: PHP search

Post by jackpf »

No, you'd put it in the php script doing the processing.

Maybe you should take a look at some PHP tutorials...if you plan on having a PHP based website, I think you should at least know how it works. From what you've posted, this doesn't seem to be the case.
Post Reply