Page 1 of 1

PHP search

Posted: Mon Aug 10, 2009 11:32 am
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.

Re: PHP search

Posted: Mon Aug 10, 2009 11:40 am
by aceconcepts
So, what are you trying to do exactly? Give us an explanation of your objective.

Re: PHP search

Posted: Mon Aug 10, 2009 11:42 am
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);

Re: PHP search

Posted: Mon Aug 10, 2009 11:53 am
by tom_haire50
Where would I insert that code?

Re: PHP search

Posted: Mon Aug 10, 2009 1:02 pm
by jackpf
8O

Re: PHP search

Posted: Mon Aug 10, 2009 1:28 pm
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.

Re: PHP search

Posted: Mon Aug 10, 2009 1:28 pm
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.