2
1

More than 1 year has passed since last update.

ヒアドキュメントサンプルプログラム(PHP)

Last updated at Posted at 2022-12-16

PHPでヒアドキュメントのサンプルプログラムをじっそうしました。

<html lang="ja">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Heredocument1</title>
  <style>
    p {
      font-size:25px;
      color:pink;
    }
  </style>  
</head>
<body>
  <?php
    $name = "秋元真夏";

    $text  = <<< EOL
      $name は乃木坂46のキャプテンです <br>
      $name の必殺技は「ズッキュン」です <br>
      $name は乃木坂46最年長メンバーです <br>
    EOL;
    
    echo "<p>${text}</p>";
  ?>

PHP部分で

<?php
    $name = "秋元真夏";

    $text  = <<< EOL
      $name は乃木坂46のキャプテンです <br>
      $name の必殺技はズッキュンです <br>
      $name は乃木坂46最年長メンバーです <br>
    EOL;
    
    echo "<p>${text}</p>";
  ?>

変数をEOLを使って囲んでヒアドキュメントを作ります。

2
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
2
1