I have searched far and wide here but with no solution to my problem (php).
Scenario: User visits a login page with a pre-assigned registration number (in datafile.txt), when entering the number in the field, script searches file if number(s) exists.
If it does exist, goes on to the next step. When the next step has been completed, I would like it to automatically “delete” the number(s) originally used once done.
I believe a “search and replace” is the way to go, while searching for an “exact” match.
My data file would resemble the following: (datafile.txt)
0
12
123
1234
12345
123456
12, would not be the same as 123 if searched.
A script that I was so kindly given a few days ago is this to accomplish another task:
$numbers = file_get_contents("datafile.txt");
$uNumber = $_POST['uNum'];
if ( @preg_match( "/([^0-9]{$uNumber}[^0-9])/", $numbers ) ) {
echo "Numbers match";
}
What I tried to do for a new task, was the following but with no success:
$numbers = file_get_contents('datafile.txt', 'w+');
$uNumber = $_POST['uNum'];
if ( @preg_match( "/([^0-9]{$uNumber}[^0-9])/", $numbers ) ) {
$numbers = preg_replace('.$_Post["uNum"]','',$numbers);
echo "Existed but will be deleted from file. ";
} else {
echo "Message showed if not in file.";
}
Any help will be greatly appreciated.
How about this one:
OR:
this should somehow work. 😀