Jump to content

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

If say I wanted to search both of the following:

 

$number = str_replace(' ', '', $data[$key][9]);
$numberb = str_replace(' ', '', $data[$key][11]);

 

How would I incorporate that into preg_match?

 

if (preg_match("/^$searchb/i", $number, $numberb)) {

 

Is that correct?

Link to comment
https://forums.phpfreaks.com/topic/106421-search-problem/#findComment-545525
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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.