Hi everyone i want to search the text file,using pregmatch() but it seems like
it dose't serch.maybe my serching pattern is not right.look at the following code.
Myfile look like this
--------------------------------
file : (49/06/01) [2007] simon 13;
file : (68/05/01) [2007] John 17 ;
i want to serch [2007] simon 13 on the text file.
can anyone help me with pregmatch patterns.
[code=php]
<?php
$jaar = $_POST[year];
$name = $_POST[name];
$empno = $_POST[employeeno];
$file =$q."Myfile.txt "; // q =path to myfile
$toSearch = "[".$jaar."]"." ".$name." ".$empno;
$lines = file($file);
$count;
$lineNumbers;
if ($lines)
{
foreach($lines as $lineNumber)
{
$lineNumbers++;
$foundAMatch = preg_match("/$toSearch/i", $lineNumber, $matches, PREG_OFFSET_CAP TURE);
if ($foundAMatch > 0)
{
$found = $matches[0][0];
$count=$lineNum ber;
echo $lineNumber."<b r />";
}
}
//$str_array = explode(" ",$count);
//echo $str_array[0]."<br/>";
}
else
{
$line="no file/folder found";
echo $line;
}
?>[/code]
it dose't serch.maybe my serching pattern is not right.look at the following code.
Myfile look like this
--------------------------------
file : (49/06/01) [2007] simon 13;
file : (68/05/01) [2007] John 17 ;
i want to serch [2007] simon 13 on the text file.
can anyone help me with pregmatch patterns.
[code=php]
<?php
$jaar = $_POST[year];
$name = $_POST[name];
$empno = $_POST[employeeno];
$file =$q."Myfile.txt "; // q =path to myfile
$toSearch = "[".$jaar."]"." ".$name." ".$empno;
$lines = file($file);
$count;
$lineNumbers;
if ($lines)
{
foreach($lines as $lineNumber)
{
$lineNumbers++;
$foundAMatch = preg_match("/$toSearch/i", $lineNumber, $matches, PREG_OFFSET_CAP TURE);
if ($foundAMatch > 0)
{
$found = $matches[0][0];
$count=$lineNum ber;
echo $lineNumber."<b r />";
}
}
//$str_array = explode(" ",$count);
//echo $str_array[0]."<br/>";
}
else
{
$line="no file/folder found";
echo $line;
}
?>[/code]
Comment