|Finding an exact match|
| 12:03 am on May 27, 2012 (gmt 0)|
Need to find an exact match from within a .txt or .htm file and there could be an empty space before any given number.
The code I tested below finds it, but not an exact match; what am I doing wrong?
$filename = 'if3.txt';
//$searchfor = '/^123456$/';
// $searchfor = "/\b123456/\b";
// $searchfor = '/\b123456\b/i';
$searchfor = '/^123/';
$file = file_get_contents($filename);
// if(strstr("\b$file\b", $searchfor))
echo "String found";
| 1:42 am on May 27, 2012 (gmt 0)|
you can't mix and match search patterns with the wrong search function as stristr() and preg_match() don't do the same thing, one uses regular expressions, the other does not,
| 2:11 am on May 27, 2012 (gmt 0)|
I understand. My fault, the mix and match in my example were commented and I should not have posted my entire "test" script.
The idea behind this, that I want to create a login page where, if a "specific" pre-determined registration number is given/sent to the user, the visits the login page and the number(s) exists in the file, to execute / login rights allowed.
For example, if a user's registration number is 12345 while another is 123, would like to first search to see if the user's number exists, then do something().
Therefore, searching for "12345" would not be the same if "123" exists already as would be the same for "234", so it has to find a specific number or numbers.
1) The person visits the initial page
2) The person enters the number code assigned
3) When clicking on "submit", checks to see if number exists in file
4) If exact number match exists, proceed to the page.
5) If match is not found, show a message.
If it makes a difference, there stands to be a "space" before and/or after the number(s).
This would be in an existing file and probably not in any specific order.
| 11:19 pm on Jun 1, 2012 (gmt 0)|
Just trim() the number of any whitespace.