LoginSignup
0
0

More than 5 years have passed since last update.

PHP 基本的なコードのメモ

Posted at

文字列の表示

<?php
echo '文字列';
?>

変数の表示

<?php
echo $a;
?>

文字列をテキストファイルに保存する

<?php
file_put_contents("sample.txt", "文字列");
?>

※ファイルが存在しない場合は自動的に作成される。

テキストファイルを読み込んで表示させる

<?php
        //fopen でファイルを開く。"r"は読み込みモード。
        $fp = fopen("sample.txt", "r");

     //whileで行末までループ処理。
        while (!feof($fp)) { 

       //fgetでファイルを読み込み、変数に格納。
            $txt = fget($fp);

       //読み込んだ変数を出力。"<br />"で改行。
            echo $txt."<br />"; 
        }

     //fcloseでファイルを閉じる。
        fclose($fp);
?>
0
0
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
0
0