Jump to content

Search Problem


Schlo_50

Recommended Posts

Hey guys,

 

I have a problem and am in need of some assistance. I want to make a search facility to search for people by their telephone number. I have had a go but am running into problems with the results. Using the code below what happens is, if I search for '07' to find all mobile numbers I actually get every number with the combination '07' within it. E.g: '07' might find 07795986251 and 01207456658, but i only want the first.

 

Can somebody help?

 

                          $lines = file("data/vacancies.DAT");
	foreach ($lines as $line) { 
		$data[$key] = explode("|", $line);

		$number = str_replace(' ', '', $data[$key][7]);
		$searchb = str_replace(' ', '', $_POST['c']);
		if (preg_match("/$searchb/i", $number)) {

		print "match.<br />";
		}

		}

 

Thanks in advance!

Link to comment
https://forums.phpfreaks.com/topic/106421-search-problem/
Share on other sites

 

 

<?php
                          $lines = file("data/vacancies.DAT");
	foreach ($lines as $line) { 
		$data[$key] = explode("|", $line);

		$number = str_replace(' ', '', $data[$key][7]);
		$numberb = str_replace(' ', '', $data[$key][11]);
		$searchb = str_replace(' ', '', $_POST['c']);
		//finds $number at the start and must contain $numberb anywhere
		if (preg_match("/^$searchb/i", $number) && preg_match("/$searchb/i", $numberb)) {

		print "match.<br />";
		}

		}
?>

Link to comment
https://forums.phpfreaks.com/topic/106421-search-problem/#findComment-545693
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.