0

ここ数週間これに取り組んできましたが、別のルートが見つかりません。私がする必要があるのは、ファイルが読み取られた後にテキスト ファイルの内容を返すことです。テキスト ファイルを使用してエラーを記録する 2 つの異なるログがあります。最初のログは、要求した正しい変数を返しますが、何らかの理由で、まったく同じメソッドを使用して変数を呼び出しても、何も返されません。変数をエコーすると、正しい文字列が表示されますが、変数は何も返しません。関数は次のとおりです。

function GetNoticeLog($strDate){
    $logdate = preg_replace("/[^0-9]/", "_", $strDate );
    $strFileName = realpath('debuglogs/enotice_logs').'/ENOTICELOG_' . $logdate . '.txt';
    if(is_readable($strFileName)){
            $file = fopen($strFileName,"r");
            $contents = fread($file, filesize($strFileName));
            $fclose($file);
            return nl2br($contents);
    }
    else if(!is_readable($strFileName)){
            echo $strFileName." is unreadable";
    }               
}

この関数が 1 つの関数で実行されたときに必要な文字列を返すのに、他の関数のコンテンツを表示するためにエコーする必要があるのはなぜですか?

4

1 に答える 1

0

変更してみる

$fclose($file);

これに

fclose($file);

サーバーでコードを動作させることができました。ここで行った唯一の変更は、PHP スクリプトと同じディレクトリにあるファイルへのパスです。

<?php

function GetNoticeLog($strDate){
    $logdate = preg_replace("/[^0-9]/", "_", $strDate );
    //$strFileName = realpath('debuglogs/enotice_logs').'/ENOTICELOG_' . $logdate . '.txt';
    $strFileName = "blah.txt";
    if(is_readable($strFileName)){
            $file = fopen($strFileName,"r");
            $contents = fread($file, filesize($strFileName));
            fclose($file);
            return nl2br($contents);
    }
    else if(!is_readable($strFileName)){
            echo $strFileName." is unreadable";
    }               
}



$stuff = GetNoticeLog("whatever");

echo $stuff;

?>
于 2013-12-29T23:27:20.443 に答える