カテゴリー
PHP

書き込みインデックス(newpage10.php)

<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="GENERATOR" content="JustSystems Homepage Builder Version 18.0.14.0 for Windows">
<title>山爺のPHP試行錯誤実験室</title>
<link rel="stylesheet" type="text/css" href="table.css" id="HPB_TABLE_CSS_ID_">
</head>
<body background="y8b.gif">
<p><img src="logo12.gif" width="377" height="45" border="0" alt="山爺のPHP試行錯誤実験室"></p>
<p>ホームページビルダーVer18でPHPの試行錯誤の実験を行っていきます。</p>
<table border="1" width="100%" cellspacing="0" cellpadding="2" id="HPB_TABLE_5_A_200520105336" class="hpb-cnt-tb1">
  <tbody>
    <tr>
      <th class="hpb-cnt-tb-th1" width="200">言語の種類</th>
      <th class="hpb-cnt-tb-th1" width="384">実行の名称</th>
      <th class="hpb-cnt-tb-th1" width="230">参考ブログ</th>
    </tr>
    <tr>
      <td class="hpb-cnt-tb-cell1" height="47" width="211" align="center">PHP_No1</td>
      <td class="hpb-cnt-tb-cell2" height="47" width="384" align="center">トップページ</td>
      <td class="hpb-cnt-tb-cell1" height="47" align="center"><a href="http://isamrx72.wpblog.jp/2020/05/20/%e5%b1%b1%e7%88%ba%e3%81%aephp%e8%a9%a6%e8%a1%8c%e9%8c%af%e8%aa%a4%e5%ae%9f%e9%a8%93%e5%ae%a4%e3%81%aeindex-php/">index.php</a></td>
    </tr>
    <tr>
      <td class="hpb-cnt-tb-cell1" height="47" width="211" align="center"></td>
      <td class="hpb-cnt-tb-cell2" height="47" width="384" align="center">書き込みインデックス</td>
      <td class="hpb-cnt-tb-cell1" height="47" align="center">newpage10.php</td>
    </tr>
  <tr>
      <td class="hpb-cnt-tb-cell1" height="47" width="211" align="center">newpage2.php</td>
      <td class="hpb-cnt-tb-cell2" height="47" width="384" align="center"><a href="newpage2.php">今日の日付と一致するか?</a></td>
      <td class="hpb-cnt-tb-cell1" height="47" align="center"><a href="http://isamrx72.wpblog.jp/2020/05/18/php%e8%a9%a6%e8%a1%8c%e9%8c%af%e8%aa%a4%e3%81%ae%e6%97%a5%e8%a8%98%e3%81%9d%e3%81%ae1/">f文の例</a></td>
    </tr>

    <tr>
      <td class="hpb-cnt-tb-cell1" height="47" width="211" align="center">newpage1.php</td>
      <td class="hpb-cnt-tb-cell2" height="47" width="384" align="center"><a href="newpage1.php">今日の日付</a></td>
      <td class="hpb-cnt-tb-cell1" height="47" align="center"><a href="http://isamrx72.wpblog.jp/2020/05/20/%e4%bb%8a%e6%97%a5%e3%81%ae%e6%97%a5%e4%bb%98%e3%80%81date%e9%96%a2%e6%95%b0/">date関数</a></td>
    </tr>
    <tr>
      <td class="hpb-cnt-tb-cell1" height="47" width="211" align="center">newpage3.php</td>
      <td class="hpb-cnt-tb-cell2" height="47" width="384" align="center"><a href="newpage3.php">100以下の2の階乗</a></td>
      <td class="hpb-cnt-tb-cell1" height="47" align="center"><a href="http://isamrx72.wpblog.jp/2020/05/19/php%e8%a9%a6%e8%a1%8c%e9%8c%af%e8%aa%a4%e5%ae%9f%e9%a8%93%e5%ae%a4%e3%81%9d%e3%81%ae2/">for文、if文(break)の使用例</a></td>
    </tr>
    <tr>
      <td class="hpb-cnt-tb-cell1" height="47" width="211" align="center">newpage4.php</td>
      <td class="hpb-cnt-tb-cell2" height="47" width="384" align="center"><a href="newpage4.php">2バイト文字列関数</a></td>
      <td class="hpb-cnt-tb-cell1" height="47" align="center"><a href="http://isamrx72.wpblog.jp/2020/05/20/mb_convert_encoding%e9%96%a2%e6%95%b0%e3%81%ae%e4%bd%bf%e7%94%a8%e4%be%8b/">mb_convert_encoding関数</a></td>
    </tr>
    <tr>
      <td class="hpb-cnt-tb-cell1" height="47" width="211" align="center">newpage5.php</td>
      <td class="hpb-cnt-tb-cell2" height="47" width="384" align="center"><a href="newpage5.php">関数の使用例</a></td>
      <td class="hpb-cnt-tb-cell1" height="47" align="center"><a href="http://isamrx72.wpblog.jp/2020/05/21/%e9%96%a2%e6%95%b0%e3%81%ae%e4%bd%9c%e6%88%90%e4%be%8b/">関数での&lt;FONT&gt;の使い方</a></td>
    </tr>
    <tr>
      <td class="hpb-cnt-tb-cell1" height="47" width="211" align="center">newpage6.php</td>
      <td class="hpb-cnt-tb-cell2" height="47" width="384" align="center"><a href="newpage6.php">関数(値渡しと参照渡し)</a></td>
      <td class="hpb-cnt-tb-cell1" height="47" align="center"><a href="http://isamrx72.wpblog.jp/2020/05/23/%e5%a4%89%e6%95%b0%e3%81%ae%e3%82%a4%e3%83%b3%e3%82%af%e3%83%ab%e3%83%bc%e3%83%89/">例題</a></td>
    </tr>
    <tr>
      <td class="hpb-cnt-tb-cell1" height="47" width="211" align="center">newpage7.php,newpage8.php</td>
      <td class="hpb-cnt-tb-cell2" height="47" width="384" align="center">newpage7.phpとnewpage8.phpで関数と変数をインクルード</td>
      <td class="hpb-cnt-tb-cell1" height="47" align="center"><a href="http://isamrx72.wpblog.jp/2020/05/23/%e9%96%a2%e6%95%b0%e3%81%ae%e3%82%a4%e3%83%b3%e3%82%af%e3%83%ab%e3%83%bc%e3%83%89/">関数のインクルード</a></td>
    </tr>
    <tr>
      <td class="hpb-cnt-tb-cell1" height="47" width="211" align="center">newpgage9.php</td>
      <td class="hpb-cnt-tb-cell2" height="47" width="384" align="center"><a href="newpage9.php">ページを作成する例</a></td>
      <td class="hpb-cnt-tb-cell1" height="47" align="center"><a href="http://isamrx72.wpblog.jp/2020/05/25/php%e3%81%a7html%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab%e3%82%92%e4%bd%9c%e3%82%8b/">phpでhtml形式を作る</a></td>
    </tr>
   <tr>
      <td class="hpb-cnt-tb-cell1" height="47" width="211" align="center">newpage11.php</td>
      <td class="hpb-cnt-tb-cell2" height="47" width="384" align="center"><a href="newpage11.php">書き込みテンプレートへリンク</a></td>
      <td class="hpb-cnt-tb-cell1" height="47" align="center"><a href="http://isamrx72.wpblog.jp/2020/05/25/%e5%ae%9f%e8%a1%8c%e6%9b%b8%e3%81%8d%e8%be%bc%e3%81%bf%e3%81%ae%e3%83%86%e3%83%b3%e3%83%97%e3%83%ac%e3%83%bc%e3%83%88/">テンプレート表示</a></td>
    </tr>
   <tr>
      <td class="hpb-cnt-tb-cell1" height="47" width="211" align="center">newpage12.php</td>
      <td class="hpb-cnt-tb-cell2" height="47" width="384" align="center"><a href="newpage12.php">配列の使い方へリンク</a></td>
      <td class="hpb-cnt-tb-cell1" height="47" align="center"><a href="http://isamrx72.wpblog.jp/2020/05/25/%e9%85%8d%e5%88%97%e3%81%ae%e4%bd%bf%e3%81%84%e6%96%b9/">配列の使い方表示</a></td>
    </tr>
  <tr>
      <td class="hpb-cnt-tb-cell1" height="47" width="211" align="center"></td>
      <td class="hpb-cnt-tb-cell2" height="47" width="384" align="center"></td>
      <td class="hpb-cnt-tb-cell1" height="47" align="center"></td>
    </tr>


  </tbody>
</table>
<p><a href="index.php">トップページへ戻る</a></p>
</body>
</html>

今時点の書き込みのインデックスなので、続けて書いていけば、増えるの変わります。構造は同じです。

カテゴリー
PHP

配列の使い方

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="ja">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta name="GENERATOR" content="JustSystems Homepage Builder Version 18.0.14.0 for Windows">
<title></title>
</head>
<body>
 <?php
  require_once ("newpage8.php");
  print $APPTITLE;

  $room[0] = "鈴木";
  $room[1] = "佐藤";
  $room[2] = "伊藤";
  $room[3] = "高橋";
  for($i = 0; $i<4; $i++){
    print $room[$i] . "<BR>";
  }

  print "$APPFOOTER";

?>

<p><a href="newpage10.php">書き込みインデックスへ戻る</a></p>
</body>
</html>

変数名に$が付くようです。タイプは無いようですね。

カテゴリー
PHP

実行書き込みのテンプレート

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="ja">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta name="GENERATOR" content="JustSystems Homepage Builder Version 18.0.14.0 for Windows">
<title></title>
</head>
<body>
 <?php
  require_once ("newpage8.php");
  print $APPTITLE;


  print "$APPFOOTER";

?>

<p><a href="newpage10.php">書き込みインデックスへ戻る</a></p>
</body>
</html>

phpのコードは上のブロックの二つのprintの間に書きます。

カテゴリー
PHP

phpでhtmlファイルを作る

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="ja">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta name="GENERATOR" content="JustSystems Homepage Builder Version 18.0.14.0 for Windows">
<title></title>
</head>
<body>
<?php
require_once("newpage7.php");
print $HTMLHEADER;
print $APPTITLE;
print "<BR>悩んでます??";
print $HTMLFOOTER;
?>
</body>
</html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta name="GENERATOR" content="JustSystems Homepage Builder Version 18.0.14.0 for Windows">
<?php
  $APPTITLE = "試行錯誤試験中です!";

  $HTMLHEADER = "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'>
  <HTML>
  <HEAD>
  <META http-equiv='Content-Type' content='text/html; charset=Shift_JIS'>
  <META http-equiv='Content-Style-Type' content='text/css'>
  <TITLE>" . $APPTITLE . "</TITLE>
  </HEAD>
  <BODY>
  <A href='newpage10.php'>書き込みインデックスへ戻る</A>
";

  $HTMLFOOTER= "</body>
                </html>";
?>

上のブロックが実際にhtmlを作ってますが、書式のみはそうですが、実際にファイルがあるわけでもないようです。下のブロックでは上で使うグローバルな変数を用意してます。下のphpファイルの名前はnewpage7.phpですが、リンクの状態を表示では、表示されません。また、転送すべきファイルにもありません。強制的にエディタで開いて、訂正出来ましたが、phpとの関連ではうまくないようですが、この場合は上手く行ったようです。

カテゴリー
PHP

変数のインクルード

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="ja">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta name="GENERATOR" content="JustSystems Homepage Builder Version 18.0.14.0 for Windows">
<title></title>
</head>
<body>
 <?php
  require_once ("newpage8.php");
  print $APPTITLE;

function SampFuncNo1() {
  print "値渡し<BR>";
  print "ポイント2 → $vol<BR>";
  $vol = $vol * 2;
  print "ポイント3 → $vol<BR>";
  return $vol;
}
function SampFuncNo2(&$a) {
  print "参照渡し<BR>";
  print "ポイント2 → $a<BR>";
  $a = $a * 2;
  print "ポイント3 → $a<BR>";
  return $a;
}

  MyTitlePrint("実験開始!関数(値渡しと参照渡し)");
  $vol = 100;
  print "<HR>";
  print "ポイント1 → $vol<BR>";
  $ret = SampFuncNo1($vol);
  print "ポイント4 → $vol<BR>";

  $vol = 100;
  print "<HR>";
  print "ポイント1 → $vol<BR>";
  $ret = SampFuncNo2($vol);
  print "ポイント4 → $vol<BR>";

?>

<p><a href="index.php">トップページへ戻る</a></p>

</body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="ja">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta name="GENERATOR" content="JustSystems Homepage Builder Version 18.0.14.0 for Windows">
<title></title>
</head>
<body>
  <?php
  function MyTitlePrint($str){
    print "<H2>$str</H2>";
    return;
  }
  function fontcolor($moji, $color) {
    $a = "<B><FONT color='$color'>" . $moji . "</FONT></B>";
    return $a;
  }

  $a = "<H2>山爺の";
  $a .= fontcolor("PHP", "#6666FF");
  $a .= fontcolor("試行錯誤的実験室", "FF0000") . "</H2><BR>";
  $APPTITLE = $a;

  ?>
</body>
</html>

前にアップした時と違ってきているので、newpage8.php関数の値渡しと参照渡し例を再度表示します。

カテゴリー
PHP

関数のインクルード

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="ja">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta name="GENERATOR" content="JustSystems Homepage Builder Version 18.0.14.0 for Windows">
<title></title>
</head>
<body>
<?php
function MyTitlePrint($str){
  print "<H2>$str</H2>";
  return;
}
?>
</body>
</html>

上は関数です。

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="ja">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta name="GENERATOR" content="JustSystems Homepage Builder Version 18.0.14.0 for Windows">
<title></title>
</head>
<body>
<?php
require_once("newpage7.php");
function fontcolor($moji, $color) {
  $a = "<B><FONT color='$color'>" . $moji . "</FONT></B>";
  return $a; 
}

  MyTitlePrint("山爺の実験開始!関数(スクリプトとHTMLの混在");
  fontcolor("PHP", "#FF0000");
  print "<BR>";
  $a = "PHPはスクリプトと";
  $a .= fontcolor("HTMLを混在できます!", "#6666FF" . "<BR>");
  print $a;

?>
<p><a href="index.php">トップページへ戻る</a></p>

</body>
</html>

 上は関数を呼ぶ側です。newpage7.phpはindex.phpと同じディレクトリーに入れてあることが条件です。require_once(“newpage7.php”);と書くことによって、MyTitlePrint(“xxx”);をここで定義した関数fontcolorと同じように呼び出せるようです。

カテゴリー
PHP

関数(値渡しと参照渡し)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="ja">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta name="GENERATOR" content="JustSystems Homepage Builder Version 18.0.14.0 for Windows">
<title></title>
</head>
<body>
 <?php
function SampFuncNo1($vol) {
  print "値渡し<BR>";
  print "ポイント2 → $vol<BR>";
  $vol = $vol * 2;
  print "ポイント3 → $vol<BR>";
  return $vol;
}
function SampFuncNo2(&$a) {
  print "参照渡し<BR>";
  print "ポイント2 → $a<BR>";
  $a = $a * 2;
  print "ポイント3 → $a<BR>";
  return $a;
}

  $vol = 100;
  print "<HR>";
  print "ポイント1 → $vol<BR>";
  $ret = SampFuncNo1($vol);
  print "ポイント4 → $vol<BR>";

  $vol = 100;
  print "<HR>";
  print "ポイント1 → $vol<BR>";
  $ret = SampFuncNo2($vol);
  print "ポイント4 → $vol<BR>";

?>

<p><a href="index.php">トップページへ戻る</a></p>

</body>
</html>

 参照渡しを受ける方の変数名に&が付きますが、呼ぶ方は値渡しと参照渡しの違いは無いようです。あやふやな記憶でC#やC++とも違うようです。

カテゴリー
PHP

関数の作成例

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="ja">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta name="GENERATOR" content="JustSystems Homepage Builder Version 18.0.14.0 for Windows">
<title></title>
</head>
<body>
<?php
function fontcolor($moji, $color) {
  print "<B><FONT color='$color'>" .
        $moji .
        "</FONT></B>";
}

  fontcolor("PHP", "#FF0000");
  print "<BR>";
  print "PHPはスクリプトと";
  fontcolor("HTMLを混在できます!", "#6666FF");
  print "<BR>";

?>
</body>
</html>

http://isamstar2.starfree.jp/newpage5.php

htmlのタグを良く知りませんので、例題そのままです。

カテゴリー
PHP

山爺のPHP試行錯誤実験室のindex.php

<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="GENERATOR" content="JustSystems Homepage Builder Version 18.0.14.0 for Windows">
<title>山爺のPHP試行錯誤実験室</title>
<link rel="stylesheet" type="text/css" href="table.css" id="HPB_TABLE_CSS_ID_">
</head>
<body background="y8b.gif">
<p><img src="logo12.gif" width="377" height="45" border="0" alt="山爺のPHP試行錯誤実験室"></p>
<p>ホームページビルダーVer18でPHPの試行錯誤の実験を行っていきます。</p>
<p><a href="newpage10.php">書き込みインデックスへ</a></p>
</body>
</html>

hpbの編集機能を使いました。前はいきなり、書き込みのインデックスだったので、もう一段かませました。

カテゴリー
PHP

今日の日付、date関数

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="ja">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta name="GENERATOR" content="JustSystems Homepage Builder Version 18.0.14.0 for Windows">
<title></title>
</head>

<?php
  print "<HR>";
  print "<DIV align='center'>";
  print "<BR>";
  print "現在の日付は " . date("Y年m月d日 h時i分") . "です。<BR>";
  print "<BR>";
  print "</DIV>";
  print "<HR>";
?>
</html>
inserted by FC2 system