I’m having problems writing a php function to search for a certain text in a php file. I’m not good with regular expressions so I think that’s the problem.
I need the regular expression to have a start word and end word and should return the text found in between.
This is what I tried:
$handle1 = fopen($file, "r");
$fileContents = fread($handle1,filesize($file));
if (preg_match('/'.$start. '((.|\n)*)'. $end.'/', $fileContents, $match)) {
$text=preg_split('/'.$start.'((.|\n)*)'. $end.'/', $match[0]);
echo $text. " found in $file<br/>";
}
Can anybody help please ?
Where
$strshould be the contents of your file.Have a look at: http://www.php.net/manual/en/reference.pcre.pattern.modifiers.php for the
i,mandsmodifiers.