我有以下PHP脚本。它的工作正常,当Array [5]有一个值而Array [4]是=" test"时,但当Array [5]没有值时,它就不起作用。
// get file
$file = "latest.log";
// test if file exists
if(!file_exists($file)) {
die("file not found");
}
while(TRUE) {
// open file
$file = escapeshellarg($file);
$file_handle = `tail -n 1 $file`;
# get line & convert to array
$array = explode(' ', $file_handle);
这很好用,当我执行这个时,我得到以下数组:
数组(
[0] => [11:14:59] [1] => [Server [2] => thread/INFO]: [3] => KaiAlexander [4] => test
)
$player_name = str_replace("<", "", $array[3]);
$player_name = str_replace(">", "", $player_name);
$array[3] = $player_name;
echo('Text: ' . $array[4] ." von " . $player_name);
echo "<pre>";
print_r($array);
echo "</pre>"; //Prints the array on top
if ($array[4] == "test") {
echo("works");
} else {
echo($array[4]);
//Echo the correct value "test"!
}
}
我不明白这个错误...... in_array
它也会这样做。