4
5

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でHTML中の特定の部分の表示をオン・オフする方法

Last updated at Posted at 2015-05-28

PHPは主にHTMLの内容を動的に変更するために使われます。

<?php
  $name = 'Taro'; // ここを変えると、HTMLのメッセージが変わる
?>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
  <h1>Hello <?php echo $name; ?>!</h1>
</body>
</html>
<?php 
    $show = 2; // ここを1,2,3と変えると、HTMLの表示が変わる
?>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    
    <?php if ($show == 1) { ?>
        <h1>Hello One!</h1>
    <?php } ?>
    
    <?php if ($show == 2) { ?>
        <h1>Hello Two!!</h1>
    <?php } ?>
    
    <?php if ($show == 3) { ?>
        <h1>Hello Three!!!</h1>
    <?php } ?>
</body>
</html>
4
5
1

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
4
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?