Alesfatalis
Alesfatalis

Reputation: 777

check for string in txt file on remote server

Hey guys im trying to search for the word Error in different subfolders on a remote Server. To enter the subfolders i use a variable in the path. My code is not working it always outputs Not Found, but for testing i inserted in a few .txt files the Word ERROR. So whats wrong with my Code?

$file_to_check = 'file://Bgsttc11/Backup/'.$stask[$j][1].'/log.txt';
            echo $path_to_check.'<br>';
            if (strstr($path_to_check, 'ERROR')) {
            echo 'found<br>';
            } 
            else {
            echo 'not found<br>';
            }

Upvotes: 0

Views: 111

Answers (1)

Mihai Iorga
Mihai Iorga

Reputation: 39704

You could use stripos() for case insensitive and if the string exists, and you are checking the file name and not contents:

$file_to_check = '\\\\bgsttc11\\Backup\\'.$stask[$j][1].'\\log.txt';
$position = stripos(implode('', file($path_to_check)), 'ERROR');
if ($position !== false) {
    echo 'found at position '.$position.'<br />';
} else {
    echo 'not found<br />';
}

Upvotes: 1

Related Questions