4
I would like to know how to compare the contents of a string in PHP.
I’m looking for a word on a line, but I don’t know what position she’s in.
$ch_atend
if($linha == "idle") { $ch_atend = $ch_atend++; };
That code is inside a While and the purpose is to go line by line to count how many times the word appears IDLE.
Good morning. <br/> I tried this way and returned 0 and the file has an Idle word. <br> '<? php $file = fopen("agents.txt", "r"); if($file == false) { print "Could not open the file"; } $ch_atend = 0; while(true) { $line = fgets($file); if($line==NULL) { break; } echo $line." <br />"; } $cont_idle = substr_count($line, "Idle"); echo $cont_idle; fclose($file); ?>
– fabricio_wm
At the moment you are checking, the line is null. Move the check inside the loop, or check the entire file at once.
– bfavaretto
I figured it was Null, just didn’t know what to do. Thanks.
– fabricio_wm