LoginSignup
5
3

More than 5 years have passed since last update.

PHP テキストファイルを読み込み、配列に格納し、表示させる。(※1行ずつの内容がそれぞれ配列の要素となるように)

Posted at
test.txt
aaa
bbb
ccc

このテキストファイルを読み込み、各行を配列に格納し、表示する。

<?PHP
  $file_name = "test.txt"; /*読込ファイルの指定*/

  $ret_array = file( $file_name ); /*ファイルを全て配列に入れる*/

    print_r($ret_array);
?>

ブラウザ上で実行すると以下のように表示される。
スクリーンショット 2018-09-18 16.23.30.png

今回使用したfile関数は、テキストファイルを行ごとに配列にして返すという特徴を持つ。

5
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
3