<?php //ファイルを読み込み専用で開く $fileName = "file.cgi"; $file = fopen($fileName,"r"); //fgetsでファイルを読み込み //1行読み込み //whileで順次読み込み表示 //feofで、ファイルの終端を判断 while(!feof($file)){ $str = fgets($file); print "$str<BR>"; } //閉じる fclose($file); ?> |
fopen→fgets→fcloseの他に、file_get_contentsを利用すれば、ファイルの内容を全て文字列にして、取得が可能です。
<?php //file_get_contentsでファイルを読み込む //ファイルの内容を全て文字列で読み込みます。 $fileName = "file.cgi"; $str = file_get_contents($fileName); print "$str"; ?> |
没有评论:
发表评论