Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
1
10php
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Yu Kimiduka
10php
Commits
54da25f0
Commit
54da25f0
authored
Jul 26, 2016
by
君塚 悠
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
各プログラムにコメント追記
parent
ceca82c6
Changes
22
Show whitespace changes
Inline
Side-by-side
Showing
22 changed files
with
101 additions
and
37 deletions
+101
-37
regex.php
php/php10/day05-3/regex.php
+1
-0
guest_input.php
php/php10/day05/guest_input.php
+3
-1
guest_read.php
php/php10/day05/guest_read.php
+1
-0
guest_write.php
php/php10/day05/guest_write.php
+10
-2
rss_output.php
php/php10/day06-1/rss_output.php
+4
-3
amazon.php
php/php10/day06-2/amazon.php
+2
-1
rss.php
php/php10/day06-3/rss.php
+2
-1
pdf_create.php
php/php10/day07-1/pdf_create.php
+9
-8
graph.php
php/php10/day07-2/graph.php
+1
-0
graph_gen.php
php/php10/day07-2/graph_gen.php
+8
-2
MyAuth.php
php/php10/day08_9/MyAuth.php
+4
-2
schedule_delete.php
php/php10/day08_9/schedule_delete.php
+5
-3
schedule_download.php
php/php10/day08_9/schedule_download.php
+5
-3
schedule_read.php
php/php10/day08_9/schedule_read.php
+6
-6
schedule_record.php
php/php10/day08_9/schedule_record.php
+5
-1
schedule_record2.php
php/php10/day08_9/schedule_record2.php
+4
-1
Triangle.class.php
php/php10/day10-1/Triangle.class.php
+11
-1
call.php
php/php10/day10-1/call.php
+4
-0
Figure.class.php
php/php10/day10-2/Figure.class.php
+4
-1
Square.class.php
php/php10/day10-2/Square.class.php
+5
-0
Triangle.class.php
php/php10/day10-2/Triangle.class.php
+3
-0
call.php
php/php10/day10-2/call.php
+4
-1
No files found.
php/php10/day05-3/regex.php
View file @
54da25f0
<!-- 指定したファイルを読み込み、URLと思われる文字列を正規表現により取得し、出力する-->
<html>
<html>
<head>
<head>
<title>
正規表現によるデータ検索
</title>
<title>
正規表現によるデータ検索
</title>
...
...
php/php10/day05/guest_input.php
View file @
54da25f0
<!-- ゲストブックに書き込むフォームを表示する
送信された内容はguest_write.phpに渡される -->
<html>
<html>
<head>
<head>
<title>
ゲストブック
</title>
<title>
ゲストブック
</title>
</head>
</head>
<body>
<body>
<!-- ccc...灰色 -->
<h1
style=
"background:#cccccc"
>
ゲストブック(書き込み)
</h1>
<h1
style=
"background:#cccccc"
>
ゲストブック(書き込み)
</h1>
<!-- 入力フォーム。<form~で作成-->
<!-- 入力フォーム。<form~で作成-->
<form
method=
"POST"
action=
"guest_write.php"
>
<form
method=
"POST"
action=
"guest_write.php"
>
お名前:
お名前:
<!-- size.. maxlength...最大文字数 -->
<input
type=
"text"
name=
"name"
size=
"20"
maxlength=
"30"
/><br
/>
<input
type=
"text"
name=
"name"
size=
"20"
maxlength=
"30"
/><br
/>
メッセージ:
メッセージ:
<input
type =
"text"
name=
"message"
size=
"70"
maxlength=
"255"
/>
<br
/>
<input
type =
"text"
name=
"message"
size=
"70"
maxlength=
"255"
/>
<br
/>
...
...
php/php10/day05/guest_read.php
View file @
54da25f0
<!-- -->
<html>
<html>
<head>
<head>
<title>
ゲストブック
</title>
<title>
ゲストブック
</title>
...
...
php/php10/day05/guest_write.php
View file @
54da25f0
<?php
<?php
// guest_input.phpから入力情報を受け取り、
// 内容を指定したファイルに追記する。
// 追記するファイルを指定する第二引数を"a"をすると、追記が可能となる。
$file
=
fopen
(
"guet.dat"
,
"a"
);
$file
=
fopen
(
"guet.dat"
,
"a"
);
flock
(
$file
,
LOCK_EX
);
//ファイルをロック(他ユーザが編集できなくなる
//ファイルをロック(他ユーザが編集できなくなる
flock
(
$file
,
LOCK_EX
);
//$line変数に書き込む文字列を連結していく。\tはタブ。
//$line変数に書き込む文字列を連結していく。\tはタブ。
$line
=
date
(
"Y年 m月 d日 H:i:s"
)
.
"
\t
"
;
$line
=
date
(
"Y年 m月 d日 H:i:s"
)
.
"
\t
"
;
$line
.=
$_POST
[
'name'
]
.
"
\t
"
;
$line
.=
$_POST
[
'name'
]
.
"
\t
"
;
$line
.=
$_POST
[
'message'
]
.
"
\t
"
;
$line
.=
$_POST
[
'message'
]
.
"
\t
"
;
fputs
(
$file
,
$line
.
"
\n
"
);
fputs
(
$file
,
$line
.
"
\n
"
);
flock
(
$file
,
LUCK_UN
);
//ファイルのロックを解除
//ファイルのロックを解除
flock
(
$file
,
LUCK_UN
);
fclose
(
$file
);
fclose
(
$file
);
header
(
"Location: guest_input.php"
);
header
(
"Location: guest_input.php"
);
?>
?>
\ No newline at end of file
php/php10/day06-1/rss_output.php
View file @
54da25f0
<?php
<?php
//RSSデータを作成する
//
//外部ライブラリのインクルード
//外部ライブラリのインクルード
require_once
(
"rss10.inc"
);
require_once
(
"rss10.inc"
);
...
@@ -9,13 +12,11 @@ $objRss = new RSSWriter("http://www.wings.msn.to/",
...
@@ -9,13 +12,11 @@ $objRss = new RSSWriter("http://www.wings.msn.to/",
"dc:pblisher"
=>
"YAMADA, Yoshihiro"
,
"dc:pblisher"
=>
"YAMADA, Yoshihiro"
,
"dc:creator"
=>
"YAMADA, Yoshihiro <CQW15204@nifty.com>"
"dc:creator"
=>
"YAMADA, Yoshihiro <CQW15204@nifty.com>"
));
));
//新着情報の登録
$objRss
->
setImage
(
"http://www.wings.msn.to/image/wings.jpg"
,
$objRss
->
setImage
(
"http://www.wings.msn.to/image/wings.jpg"
,
"サーバサイド技術の学び舎 - WINGS"
,
150
,
90
);
"サーバサイド技術の学び舎 - WINGS"
,
150
,
90
);
//サマリ情報の登録
$file
=
fopen
(
"data.dat"
,
"r"
);
$file
=
fopen
(
"data.dat"
,
"r"
);
while
(
$row
=
fgets
(
"file, 1024"
))
{
while
(
$row
=
fgets
(
"file, 1024"
))
{
$datum
=
explode
(
"
\t
"
,
$row
);
$datum
=
explode
(
"
\t
"
,
$row
);
$objRss
->
addItem
(
$datum
[
0
],
$datum
[
1
],
$objRss
->
addItem
(
$datum
[
0
],
$datum
[
1
],
...
...
php/php10/day06-2/amazon.php
View file @
54da25f0
<!-- amazonの書籍DBを検索するWebサービスを利用する -->
<html>
<html>
<head>
<head>
<title>
Amazon Webサービスの活用
</title>
<title>
Amazon Webサービスの活用
</title>
...
@@ -30,7 +31,7 @@ if ($_POST['keywd'] != '') {
...
@@ -30,7 +31,7 @@ if ($_POST['keywd'] != '') {
foreach
(
$result
->
Details
as
$item
)
{
foreach
(
$result
->
Details
as
$item
)
{
?>
?>
<!-- 検索結果の
記述
-->
<!-- 検索結果の
出力
-->
<tr>
<tr>
<td>
<?php
print
(
++
$i
)
?>
</td>
<td>
<?php
print
(
++
$i
)
?>
</td>
<td>
<td>
...
...
php/php10/day06-3/rss.php
View file @
54da25f0
<!-- rss.xmlに記載したRSSデータを読み込み、出力する。 -->
<html>
<html>
<head>
<head>
<title>
RSSフィードの読み込み
</title>
<title>
RSSフィードの読み込み
</title>
...
@@ -20,7 +21,7 @@ foreach ($objXml -> site as $site) {
...
@@ -20,7 +21,7 @@ foreach ($objXml -> site as $site) {
?>
?>
<dl>
<dl>
<dt
style =
"font-weight:bold;"
>
<?php
<dt
style =
"font-weight:bold;"
>
<?php
//タイトルがnullや空でな場合はEUC-JPに変換して出力
//タイトルがnullや空でな
い
場合はEUC-JPに変換して出力
if
(
!
is_null
(
$site
->
title
)
&&
$site
->
title
!=
""
)
{
if
(
!
is_null
(
$site
->
title
)
&&
$site
->
title
!=
""
)
{
print
(
mb_convert_encoding
(
$site
->
title
,
"EUC-JP"
,
"auto"
));
print
(
mb_convert_encoding
(
$site
->
title
,
"EUC-JP"
,
"auto"
));
}
else
{
}
else
{
...
...
php/php10/day07-1/pdf_create.php
View file @
54da25f0
<?php
<?php
//PDFlib/PDIによるPDFの自動生成
//PDFlib/PDIによリ、PDFを自動生成する。
//生成するPDFは、指定したテンプレートを使用し、指定した文字列を出力する。
//PDFファイル生成
//PDFファイル生成
$objPdf
=
pdf_new
();
$objPdf
=
pdf_new
();
...
@@ -8,24 +9,24 @@ pdf_begin_document($objPdf, "", "");
...
@@ -8,24 +9,24 @@ pdf_begin_document($objPdf, "", "");
//PDFの構成文書設定(Author -> Yoshihiro yamada)
//PDFの構成文書設定(Author -> Yoshihiro yamada)
pdf_set_info
(
$obfPdf
,
"Author"
,
"Yoshihiro yamada"
);
pdf_set_info
(
$obfPdf
,
"Author"
,
"Yoshihiro yamada"
);
//テンプレートとなるファイルを指定する
//テンプレートとなるファイルを指定する
。
$objTmp
=
pdf_open_pdi
(
$objPdf
,
dirname
(
__FILE__
)
.
"/template.pdf"
,
""
,
0
);
$objTmp
=
pdf_open_pdi
(
$objPdf
,
dirname
(
__FILE__
)
.
"/template.pdf"
,
""
,
0
);
//利用するページを選択する
//利用するページを選択する
$objPag
=
pdf_open_pdi_page
(
$objPdf
,
$objTmp
,
1
,
""
);
$objPag
=
pdf_open_pdi_page
(
$objPdf
,
$objTmp
,
1
,
""
);
//PDFファイルに新規にページを追加する
//PDFファイルに新規にページを追加する
。
pdf_begin_page_ext
(
$objPdf
,
10
,
10
,
''
);
pdf_begin_page_ext
(
$objPdf
,
10
,
10
,
''
);
//テンプレートとなるファイルを作成したページに貼り付ける
//テンプレートとなるファイルを作成したページに貼り付ける
。
//adjustpageを指定することで、サイズが自動調整される
//adjustpageを指定することで、サイズが自動調整される
。
pdf_fit_pdi_page
(
$objPdf
,
$objPag
,
0
,
0
,
"adjustpage"
);
pdf_fit_pdi_page
(
$objPdf
,
$objPag
,
0
,
0
,
"adjustpage"
);
//フォントや行間などを設定する
//フォントや行間などを設定する
。
$objFnt
=
pdf_load_font
(
$objpdf
,
"HeiseiMin-W3"
,
"EUC-H"
,
""
);
$objFnt
=
pdf_load_font
(
$objpdf
,
"HeiseiMin-W3"
,
"EUC-H"
,
""
);
pdf_serfont
(
$obgPdf
,
$objFnt
,
14
);
pdf_serfont
(
$obgPdf
,
$objFnt
,
14
);
pdf_set_valuse
(
$objPdf
,
"leading"
,
20
);
pdf_set_valuse
(
$objPdf
,
"leading"
,
20
);
pdf_set_text_pos
(
$objPdf
,
100
,
600
);
pdf_set_text_pos
(
$objPdf
,
100
,
600
);
//作製したPDFに文字列を出力する
//作製したPDFに文字列を出力する
。
pdf_show
(
$objPdf
,
"サーバサイド技術の学び舎 - WINGS"
);
pdf_show
(
$objPdf
,
"サーバサイド技術の学び舎 - WINGS"
);
pdf_continue_text
(
$objPdf
,
"http://www.wings.msn.to/"
);
pdf_continue_text
(
$objPdf
,
"http://www.wings.msn.to/"
);
...
@@ -34,6 +35,6 @@ pdf_close($ogjPdf);
...
@@ -34,6 +35,6 @@ pdf_close($ogjPdf);
pdf_close_pdi
(
$objPdf
,
$objTmp
);
pdf_close_pdi
(
$objPdf
,
$objTmp
);
header
(
"Content-type: application/pdf"
);
header
(
"Content-type: application/pdf"
);
header
(
"Cotent-disposition: attachment; filename = result.pdf"
);
header
(
"Cotent-disposition: attachment; filename = result.pdf"
);
print
(
pdf_get_buffer
(
$ogjPdgf
)
print
(
pdf_get_buffer
(
$ogjPdgf
)
);
pdf_delete
(
$objPdf
);
pdf_delete
(
$objPdf
);
?>
?>
\ No newline at end of file
php/php10/day07-2/graph.php
View file @
54da25f0
<!-- graph_gen.phpで出力する棒グラフのタイトルを設定する -->
<html>
<html>
<head>
<head>
<title>
棒グラフの動的生成
</title>
<title>
棒グラフの動的生成
</title>
...
...
php/php10/day07-2/graph_gen.php
View file @
54da25f0
<?php
<?php
//JpGraphによる棒グラフの生成
//JpGraphにより、棒グラフを生成する。
//グラフタイトルは、jpgraph.phpから読み込む。
require_once
(
"jpgraph/jpgraph.php"
);
require_once
(
"jpgraph/jpgraph.php"
);
require_once
(
"jpgraph/jpgraph_bar.php"
);
require_once
(
"jpgraph/jpgraph_bar.php"
);
...
@@ -8,22 +10,26 @@ $objGrh = new Graph(450, 250, "auto");
...
@@ -8,22 +10,26 @@ $objGrh = new Graph(450, 250, "auto");
$objGrh
->
SetScale
(
"textlin"
);
$objGrh
->
SetScale
(
"textlin"
);
$objGrh
->
title
->
Set
(
"Books Trend"
);
$objGrh
->
title
->
Set
(
"Books Trend"
);
$objGrh
->
xaxis
->
title
->
Set
(
"2005.4Q"
);
$objGrh
->
xaxis
->
title
->
Set
(
"2005.4Q"
);
$objGrh
->
yaxis
->
title
->
Set
(
"Quantity"
);
$objGrh
->
yaxis
->
title
->
Set
(
"Quantity"
);
//グラフのデータ設定
//グラフのデータ設定
//大きさ
$data
=
array
(
array
(
350
,
200
,
280
),
array
(
295
,
150
,
290
),
array
(
295
,
150
,
290
),
array
(
315
,
180
,
220
));
$data
=
array
(
array
(
350
,
200
,
280
),
array
(
295
,
150
,
290
),
array
(
295
,
150
,
290
),
array
(
315
,
180
,
220
));
$objPlot
[]
=
new
BarPlot
(
$data
[
0
]);
$objPlot
[]
=
new
BarPlot
(
$data
[
0
]);
$objPlot
[]
=
new
BarPlot
(
$data
[
1
]);
$objPlot
[]
=
new
BarPlot
(
$data
[
1
]);
$objPlot
[]
=
new
BarPlot
(
$data
[
2
]);
$objPlot
[]
=
new
BarPlot
(
$data
[
2
]);
//書くグラフのタイトル
$objPlot
[
0
]
->
SetLegend
(
'PHP'
);
$objPlot
[
0
]
->
SetLegend
(
'PHP'
);
$objPlot
[
1
]
->
SetLegend
(
'ASP'
);
$objPlot
[
1
]
->
SetLegend
(
'ASP'
);
$objPlot
[
2
]
->
SetLegend
(
'ASP'
);
$objPlot
[
2
]
->
SetLegend
(
'ASP'
);
//色
$objPlot
[
0
]
->
SetFillcolor
(
'red@0.7'
);
$objPlot
[
0
]
->
SetFillcolor
(
'red@0.7'
);
$objPlot
[
1
]
->
SetFillcolor
(
'blue@0.7'
);
$objPlot
[
1
]
->
SetFillcolor
(
'blue@0.7'
);
$objPlot
[
2
]
->
SetFillcolor
(
'green@0.7'
);
$objPlot
[
2
]
->
SetFillcolor
(
'green@0.7'
);
//グラフの出力
//グラフの出力
$objGbp
=
new
GroupBarPlot
(
$objPlot
);
$objGbp
=
new
GroupBarPlot
(
$objPlot
);
//グラフ(画像)の全体幅に対する比率
$objGbp
->
SetWidth
(
0.90
);
$objGbp
->
SetWidth
(
0.90
);
$obpGrh
->
Add
(
$objGbp
);
$obpGrh
->
Add
(
$objGbp
);
$objGrh
->
Stroke
();
$objGrh
->
Stroke
();
...
...
php/php10/day08_9/MyAuth.php
View file @
54da25f0
<?php
<?php
// login.phpにアクセスする際に、
require_once
(
Auth
/
Auth
.
php
);
require_once
(
Auth
/
Auth
.
php
);
// ログインページを生成するための関数
// ログインページを生成するための関数
...
@@ -7,7 +9,7 @@ function Mylogin()
...
@@ -7,7 +9,7 @@ function Mylogin()
require_once
(
"login.php"
);
require_once
(
"login.php"
);
}
}
// 認証する
//
.phpのファイルにアクセスされた場合に、非認証であれば
認証する
$param
=
array
(
$param
=
array
(
// DBへの接続パス
// DBへの接続パス
"dsn"
=>
"sqlite://localhost/schedule.sqlite"
,
"dsn"
=>
"sqlite://localhost/schedule.sqlite"
,
...
@@ -20,7 +22,7 @@ $param = array(
...
@@ -20,7 +22,7 @@ $param = array(
$auth
=
new
Auth
(
"DB"
,
$passwd
,
"MyLogin"
,
TRUE
);
$auth
=
new
Auth
(
"DB"
,
$passwd
,
"MyLogin"
,
TRUE
);
$Auth
->
start
();
$Auth
->
start
();
if
(
$auth
->
getUsername
()
==
""
)
{
if
(
$auth
->
getUsername
()
==
""
)
{
//未承認→強制終了する
//未承認→強制終了する
exit
(
1
);
exit
(
1
);
}
}
...
...
php/php10/day08_9/schedule_delete.php
View file @
54da25f0
<?php
<?php
//データベースへの接続
// データベースから、schedule_read.phpのフォームで選択したスケジュールと一つ削除する。
// データベースへの接続
$db
=
sqlite_open
(
"schedule.sqlite"
,
0666
,
$err
);
$db
=
sqlite_open
(
"schedule.sqlite"
,
0666
,
$err
);
//SQL命令の発行
//
SQL命令の発行
sqlite_query
(
$db
,
"DELETE FROM schedule WHERE sid ='"
.
sqlite_escape_string
(
$_GET
[
'sid'
])
.
"'"
);
sqlite_query
(
$db
,
"DELETE FROM schedule WHERE sid ='"
.
sqlite_escape_string
(
$_GET
[
'sid'
])
.
"'"
);
//データベースの切断
//
データベースの切断
sqlite_close
(
$db
);
sqlite_close
(
$db
);
header
(
"Location: schedule_read.php"
);
header
(
"Location: schedule_read.php"
);
...
...
php/php10/day08_9/schedule_download.php
View file @
54da25f0
<?php
<?php
// httpヘッダの出力
// スケジュール情報をダウンロードする
// HTTPヘッダの出力
header
(
"Content-Type: application/octet-stream"
);
header
(
"Content-Type: application/octet-stream"
);
header
(
"Content-Dispsition: attachment;filename = schedule.txt"
);
header
(
"Content-Dispsition: attachment;filename = schedule.txt"
);
...
@@ -8,7 +10,7 @@ require_once ("DB.php");
...
@@ -8,7 +10,7 @@ require_once ("DB.php");
// データベースへ接続
// データベースへ接続
$db
=
DB
::
connect
(
"sqlite://localhost/achedule.sqlite"
);
$db
=
DB
::
connect
(
"sqlite://localhost/achedule.sqlite"
);
// SQL文
の発行
// SQL文
スケジュールを日時に基づいて並び替えて引き出す
$stt
=
$db
->
prepare
(
"SELECT * FROM schedule ORDER BYs_date,s_time"
);
$stt
=
$db
->
prepare
(
"SELECT * FROM schedule ORDER BYs_date,s_time"
);
$rs
=
$db
->
execute
(
$stt
);
$rs
=
$db
->
execute
(
$stt
);
...
@@ -19,6 +21,6 @@ while ($row = $rs -> fetchRow(DB_FETCHMODE_ASSOC)) {
...
@@ -19,6 +21,6 @@ while ($row = $rs -> fetchRow(DB_FETCHMODE_ASSOC)) {
print
(
mb_conert_encoding
(
$row
[
'memo'
],
"SJIS"
,
"auto"
)
.
"
\r\n
"
);
print
(
mb_conert_encoding
(
$row
[
'memo'
],
"SJIS"
,
"auto"
)
.
"
\r\n
"
);
}
}
//切断
//
切断
$db
->
disconnect
();
$db
->
disconnect
();
?>
?>
\ No newline at end of file
php/php10/day08_9/schedule_read.php
View file @
54da25f0
<?php
<?php
//データベースへ接続
// schedule_record.phpで入力されたスケジュールを出力する。
// データベースへ接続
$db
=
sqlite_open
(
"schedule.sqlite"
,
0666
,
$err
);
$db
=
sqlite_open
(
"schedule.sqlite"
,
0666
,
$err
);
//
SQL命令の発行
//
SQL命令文 日時順にスケジュールを並び替える。
$rs
=
sqlite_query
(
"SELECT * FROM schedule ORDER BY s_date, s_time"
,
$db
);
$rs
=
sqlite_query
(
"SELECT * FROM schedule ORDER BY s_date, s_time"
,
$db
);
?>
?>
<html>
<html>
...
@@ -15,7 +17,7 @@ $rs = sqlite_query("SELECT * FROM schedule ORDER BY s_date, s_time" ,$db);
...
@@ -15,7 +17,7 @@ $rs = sqlite_query("SELECT * FROM schedule ORDER BY s_date, s_time" ,$db);
<th>
日付
</th><th>
時刻
</th><th>
予定名
</th><th>
備考
</th><th>
削除
</th>
<th>
日付
</th><th>
時刻
</th><th>
予定名
</th><th>
備考
</th><th>
削除
</th>
</tr>
</tr>
//取得した結果セットを出力
<!-- 取得した結果を出力 -->
<?php
while
(
$row
=
sqlite_fetch_array
(
$rs
)){
?>
<?php
while
(
$row
=
sqlite_fetch_array
(
$rs
)){
?>
<tr>
<tr>
<td>
<?php
print
(
$row
[
's_date'
]);
?>
</td>
<td>
<?php
print
(
$row
[
's_date'
]);
?>
</td>
...
@@ -27,9 +29,7 @@ $rs = sqlite_query("SELECT * FROM schedule ORDER BY s_date, s_time" ,$db);
...
@@ -27,9 +29,7 @@ $rs = sqlite_query("SELECT * FROM schedule ORDER BY s_date, s_time" ,$db);
</tr>
</tr>
<?php
<?php
}
}
?>
// データベースの切断
<!-- データベースの切断 -->
sqlite_close
(
$db
);
sqlite_close
(
$db
);
?>
?>
</table>
</table>
...
...
php/php10/day08_9/schedule_record.php
View file @
54da25f0
<?php
<?php
// スケジュールを登録する。
// 登録したスケジュールは、schedule_read.phpにて読み込まれる。
//コンボボックスを定義する。
function
showopt
(
$start
,
$end
)
function
showopt
(
$start
,
$end
)
{
{
for
(
$i
=
$start
;
$i
<=
$end
;
$i
++
)
{
for
(
$i
=
$start
;
$i
<=
$end
;
$i
++
)
{
print
(
"<option valu
r
= '"
.
$i
.
"'>"
.
$i
.
"</option>"
);
print
(
"<option valu
e
= '"
.
$i
.
"'>"
.
$i
.
"</option>"
);
}
}
}
}
?>
?>
...
...
php/php10/day08_9/schedule_record2.php
View file @
54da25f0
<?php
<?php
//データベースを操作し、
//データベースへ接続
//データベースへ接続
$db
=
sqliyr_open
(
"schedule.sqlite"
,
0666
,
$err
);
$db
=
sqliyr_open
(
"schedule.sqlite"
,
0666
,
$err
);
$s_date
=
$_POST
[
's_date_year'
]
.
"/"
.
$_POST
[
's_date_month'
]
.
"/"
.
$_POST
[
's_date_day'
];
$s_date
=
$_POST
[
's_date_year'
]
.
"/"
.
$_POST
[
's_date_month'
]
.
"/"
.
$_POST
[
's_date_day'
];
$s_time
=
$_POST
[
's_time_hour'
]
.
":"
.
$_POST
[
's_minute'
];
$s_time
=
$_POST
[
's_time_hour'
]
.
":"
.
$_POST
[
's_minute'
];
//SQL命令
//SQL命令
文 スケジュール入力フォーム(schedule_record.php)で入力した値を挿入する
splite_query
(
$db
,
"INSERT INTO schedule(title, s_date, s_time, memo) VALUES('"
.
sqite_escape_string
(
$s_date
)
.
"','"
.
sqlite_escape_string
(
$s_time
)
.
"','"
.
sqlite_escape_string
(
$_POST
[
'memo'
])
.
"')"
);
splite_query
(
$db
,
"INSERT INTO schedule(title, s_date, s_time, memo) VALUES('"
.
sqite_escape_string
(
$s_date
)
.
"','"
.
sqlite_escape_string
(
$s_time
)
.
"','"
.
sqlite_escape_string
(
$_POST
[
'memo'
])
.
"')"
);
//データベースから切断
//データベースから切断
...
...
php/php10/day10-1/Triangle.class.php
View file @
54da25f0
<?php
<?php
//callから送られた三角形の大きさを元に、面積を返す
class
Triangle
class
Triangle
{
{
private
$width
;
private
$width
;
...
@@ -12,21 +14,29 @@ class Triangle
...
@@ -12,21 +14,29 @@ class Triangle
//デストラクタ…破棄されるときに呼び出される
//デストラクタ…破棄されるときに呼び出される
public
function
__destruct
(){
/*デストラクタ*/
}
public
function
__destruct
(){
/*デストラクタ*/
}
// 底辺の長さを返す
public
function
get_width
()
{
return
$this
->
width
;}
public
function
get_width
()
{
return
$this
->
width
;}
// 高さを返す
public
function
get_height
(){
return
$this
->
height
;}
public
function
get_height
(){
return
$this
->
height
;}
//底辺の長さを設定する
public
function
set_width
(
$width
)
{
public
function
set_width
(
$width
)
{
if
(
i_numeric
(
$width
))
{
if
(
i_numeric
(
$width
))
{
$this
->
width
=
$width
;
$this
->
width
=
$width
;
}
}
}
}
// 高さを設定する
public
function
set_height
(
$height
)
public
function
set_height
(
$height
)
{
{
if
(
is_numeric
(
$height
))
{
if
(
is_numeric
(
$height
))
{
$this
->
height
=
$height
;
$this
->
height
=
$height
;
}
}
}
}
// 免責を返す
public
function
get_area
()
public
function
get_area
()
{
{
return
$this
->
get_width
()
*
$this
->
get_height
()
/
2
;
return
$this
->
get_width
()
*
$this
->
get_height
()
/
2
;
...
...
php/php10/day10-1/call.php
View file @
54da25f0
<!-- 三角形の面積を設定した三角形の大きさから計算し、出力する -->
<html>
<html>
<head>
<head>
<title>
オブジェクト指向入門
</title>
<title>
オブジェクト指向入門
</title>
...
@@ -16,7 +18,9 @@ function __autoload($name)
...
@@ -16,7 +18,9 @@ function __autoload($name)
$objCls
=
new
Triangle
();
$objCls
=
new
Triangle
();
$objCls
->
set_width
(
10
);
$objCls
->
set_width
(
10
);
$objCls
->
set_height
(
20
);
$objCls
->
set_height
(
20
);
// 20*10の三角形の面積:事前にセッターでセットした値を使って計算する
print
(
"三角形の面積:"
.
$objCls
->
get_area
()
.
"<br>"
);
print
(
"三角形の面積:"
.
$objCls
->
get_area
()
.
"<br>"
);
// 15*5の三角形の面積:引数を使って計算する
print
(
"三角形の面積:"
.
Triangle
::
calculate_area
(
5
,
15
));
print
(
"三角形の面積:"
.
Triangle
::
calculate_area
(
5
,
15
));
?>
?>
</body>
</body>
...
...
php/php10/day10-2/Figure.class.php
View file @
54da25f0
<?php
<?php
// 図形の面積の大きさのゲッター、セッター、
// get_area()(面積を返す)を用意している、Triangle.class.php,Square.class.phpの
abstract
class
Figure
abstract
class
Figure
{
{
private
$width
;
private
$width
;
...
@@ -31,7 +34,7 @@ abstract class Figure
...
@@ -31,7 +34,7 @@ abstract class Figure
$this
->
height
=
$height
;
$this
->
height
=
$height
;
}
}
}
}
//抽象メソッド
//
抽象メソッド
public
abstract
function
get_area
();
public
abstract
function
get_area
();
}
}
?>
?>
php/php10/day10-2/Square.class.php
View file @
54da25f0
<?php
<?php
//四角形の大きさから、面積を計算して返す
//Figureを継承しているため、ゲッター、セッター、get_area()は宣言済みの扱い
class
Square
extends
Figure
class
Square
extends
Figure
{
{
public
function
__construct
()
public
function
__construct
()
{
{
parent
::
__construct
();
parent
::
__construct
();
}
}
//オーバーライド
public
function
get_area
()
public
function
get_area
()
{
{
return
$this
->
get_width
()
*
$this
->
get_height
();
return
$this
->
get_width
()
*
$this
->
get_height
();
...
...
php/php10/day10-2/Triangle.class.php
View file @
54da25f0
<?php
<?php
//三角形の大きさから、面積を計算して返す
//Figureを継承しているため、ゲッター、セッター、get_area()は宣言済みの扱い
class
Triangle
extends
Figure
class
Triangle
extends
Figure
{
{
public
function
__construct
()
public
function
__construct
()
...
...
php/php10/day10-2/call.php
View file @
54da25f0
<!-- 設定した三角形、四角形の大きさを元に、面積を求める -->
<html>
<html>
<head>
<head>
<title>
オブジェクト指向入門(ポリモーフィズム)
</title>
<title>
オブジェクト指向入門(ポリモーフィズム)
</title>
...
@@ -5,7 +6,6 @@
...
@@ -5,7 +6,6 @@
<body>
<body>
<h1
style =
"background:#cccccc"
>
オブジェクト入門(ポリモーフィズム
</h1>
<h1
style =
"background:#cccccc"
>
オブジェクト入門(ポリモーフィズム
</h1>
<?php
<?php
// autoload関数の定義
// autoload関数の定義
function
__autoload
(
$name
)
function
__autoload
(
$name
)
{
{
...
@@ -13,10 +13,13 @@ function __autoload($name)
...
@@ -13,10 +13,13 @@ function __autoload($name)
}
}
// Triangleクラス(Triangle.class.phpに有る)のインスタンス化
// Triangleクラス(Triangle.class.phpに有る)のインスタンス化
// 三角形の大きさをセットし、get_area()関数で計算する
$objTri
=
new
Triangle
();
$objTri
=
new
Triangle
();
$objTri
->
set_width
(
10
);
$objTri
->
set_width
(
10
);
$objTri
->
set_height
(
20
);
$objTri
->
set_height
(
20
);
print
(
"三角形の面積:"
.
$objTri
->
get_area
()
.
"<br>"
);
print
(
"三角形の面積:"
.
$objTri
->
get_area
()
.
"<br>"
);
// Squareクラス(Square.class.phpに有る)のインスタンス化
// 四角形の大きさをセットし、get_area()関数で計算する
$objSqr
=
new
Square
();
$objSqr
=
new
Square
();
$objSqr
->
set_width
(
10
);
$objSqr
->
set_width
(
10
);
$objSqr
->
set_height
(
20
);
$objSqr
->
set_height
(
20
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment