I loading a file from a controller and trying to find a string from that file inside a model.
The function in the controller i have written has:
<?php
public function file() {
$filename = "C:/Users/Declan/Desktop/foo.txt";
}
?>
And In the model I would have:
<?php
function find{
if( exec('grep '.escapeshellarg($_GET['bar']).'$filename')) {
echo "string found";
}
}
?>
I am using This Question as reference.
Any help would be appreciated.
When you use the exec() method who is use to run an external program. You are on windows apparently, grep is only for unix system (Linux ...).
<?php
function find($filePath, $stringToLookFor){
$handle = fopen($filePath, 'r');
$stringFound = false; // Init false
while (($buffer = fgets($handle)) !== false) { // Loop through each file line
if (strpos($buffer, $stringToLookFor) !== false) { // Check if in $buffer
$stringFound = true; // String found
}
}
fclose($handle);
return $stringFound;
}
?>