Problems using fread for if statement.

We are trying to display whether a file contains a specific string or not:

Here we read the file:

$myFile = “filename.txt”;
$fh = fopen($myFile,‘r’);
$theData = fread($fh, filesize(“filename.txt”));
fclose($fh);

File contains “Offline”

Here we are trying to compare the strings:
if(strcmp($theData,“Online”)==0){
echo “Online”; }
elseif(strcmp($theData,“Offline”)==0) {
echo “Offline”; }
else {
echo “This IF is not working.” }

We have tried using regular if without the strcomp, but it did not work either. I’m thinking that an IF cannot compare the results from the fread to a regular string. Perhaps we will need to try another method.

Any Ideas?

Is it case-sensitive or case insensitive?

case-insensitive method:
[php]if (strcasecmp($theData, “Online”) == 0) {
echo ‘Online’;
} elseif (strcasecmp($theData, “Offline”) == 0) {
echo ‘Offline’;
} else {
echo ‘Not Found’;
}[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service