LoginSignup
0
0

More than 5 years have passed since last update.

PHPの書き方

Last updated at Posted at 2018-08-08
<?php
$a = 'xoxo';
?>
  1. <?php と ?> の間に書く。
  2. 1つの命令の終わりに「;」をつける。
  3. 外部ファイルをつくって、そこにPHPを書くことも可能。htmlファイルのどこにでも外部のphpファイルを読み込める。こんなふうに↓
<?php include('hoge.php'); ?>

注意点

  • その1
<?php
 $str = 'サンプル1';
?>
<html>
 <head>
  <?php
   $str = 'サンプル2';
  ?>
  <meta charset="utf-8">
  <title>タイトル</title>
 </head>
 <body>
  <p><?php echo $str; ?></p>
 </body>
</html>

<?php echo $str; ?>で表示されるのは「サンプル2」になります。

  • その2

全角はクォーテーション、ダブルクォーテーションで囲んでないとエラーになる。全角がいつのまにか入っててエラーになることがけっこうある。

ウェブカツ!!

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