0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PHPの超基本

Last updated at Posted at 2019-12-27

目的

  • PHPをまだ部にあたり、超基本となることをまとめる

PHPはどこに書くの?

  • HTMLファイルの中に記載する。
  • 独立したファイルとして記載することも可能である。

HTMLファイル内にどうやってPHPを書くの?

  • PHPのコードは<?php?>で囲む。

  • PHPのコードをHTMLファイルの中に記載する方法を例として下記に記載する。

    <?php PHPの命令 ?>
    

PHPのコメントアウトはどうするの?

  • //の後ろがコメントとなる。
  • もちろんコメントも<?PHP ?>の中に記載する。

文末に記号は必要なの?

  • PHPは文末記号が必要である。
  • 文末には必ずセミコロン;をつける。

PHPでHello Worldはどうすればいいの?

  • 環境構築が完了しているPCで.phpファイルを作成して下記のコードを記載してブラウザで確認する

    <!DOCTYPE html>
    <html>
    <head>
      <meta charset="utf-8">
      <title>Progate</title>
      <link rel="stylesheet" type="text/css" href="stylesheet.css">
    </head>
    <body>
      <?php
       echo "Hello, world!";
      ?>
    </body>
    </html>
    
  • PHPのコードを実行できるWebサイトにて下記のコードを記載して実行する。https://paiza.io/projects/nHmsVLuX9kEybNsetTz7Tg

    <?php
    echo "Hello World";
    ?>
    
    

VM環境のローカルビルトインサーバの起動

$ cd phpのファイルがあるディレクトリ
$ php -S 自分のIP:8000
0
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?