1.HTTP REQUEST
2.HTTP RESPONSE
1.HTTP Request
2.Request Data
3.Give Data
4.HTTP Response
<?php
//這是註解
/*
這是
多行註解
*/
echo "這是輸出用的";
?>
<?php
$myVariable = '我是變數'; //宣告一個變數
echo $myVariable . '<br/>';
$myVariable = 5; //改變值
echo $myVariable . '<br/>';
?>
我是變數
5
<?php
$myVariable1 = '隔壁老王';
$myVariable2 = '小白';
$myVariable3 = '眉毛';
$myVariable4 = '肥姿姿';
$myVariable5 = '胖嘟嘟';
$myVariable6 = '鍇嘉';
$myVariable7 = '黑黑der志宇';
$myVariable8 = '柏宇神';
$myVariable9 = '小橘子';
$myVariable10 = 'Orange 神';
.
.
.
.
.
.
$myVariable100 = '右鈞神';
?>
<?php
$myArray = [1, 2, '字串也可以唷'];
$myArray2 = [1 => 'One',
2 => 'two',
'string' => '字串也可以當index'];
$myArray3 = array(1 => 'One ~',
2 => 'two ~',
'string' => 'string也可以當index');
$myArray[] = 8;
$myArray2[] = 9;
$myArray3[] = 10;
print_r($myArray);
print_r($myArray2);
print_r($myArray3);
?>
Array
(
[0] => 1
[1] => 2
[2] => 字串也可以唷
[3] => 8
)
Array
(
[1] => One
[2] => two
[string] => 字串也可以當index
[3] => 9
)
Array
(
[1] => One ~
[2] => two ~
[string] => string也可以當index
[3] => 10
)
<?php
for($i = 0 ;$i < 10 ; $i++) {
echo '$i = ' . $i . '<br>';
}
?>
<?php
for($i = 0 ;$i < 10 ; $i++) {
echo '$i = ' . $i . '<br>';
}
?>
初始值
<?php
for($i = 0 ;$i < 10 ; $i++) {
echo '$i = ' . $i . '<br>';
}
?>
執行條件
<?php
for($i = 0 ;$i < 10 ; $i++) {
echo '$i = ' . $i . '<br>';
}
?>
執行完後?
<?php
for($i = 0 ;$i < 10 ; $i++) {
echo '$i = ' . $i . '<br>';
}
?>
for-loop執行順序
A
B
C
D
A→B→D→C→(回到B繼續)
$i = 0
$i = 0
$i = 1
$i = 0
$i = 1
$i = 2
$i = 0
$i = 1
$i = 2
$i = 3
$i = 0
$i = 1
$i = 2
$i = 3
$i = 4
$i = 0
$i = 1
$i = 2
$i = 3
$i = 4
$i = 5
$i = 0
$i = 1
$i = 2
$i = 3
$i = 4
$i = 5
$i = 6
$i = 0
$i = 1
$i = 2
$i = 3
$i = 4
$i = 5
$i = 6
$i = 7
$i = 0
$i = 1
$i = 2
$i = 3
$i = 4
$i = 5
$i = 6
$i = 7
$i = 8
$i = 0
$i = 1
$i = 2
$i = 3
$i = 4
$i = 5
$i = 6
$i = 7
$i = 8
$i = 9
<?php
$i = 0 ;
while($i < 10) {
echo '$i = ' . $i . '<br>';
$i++;
}
?>
<?php
$i = 0 ;
while($i < 10) {
echo '$i = ' . $i . '<br>';
$i++;
}
?>
執行條件
$i = 0
$i = 1
$i = 2
$i = 3
$i = 4
$i = 5
$i = 6
$i = 7
$i = 8
$i = 9
<?php
$i = 0;
do{
echo '$i = ' . $i . '<br>';
$i++;
}while($i < 10);
?>
執行條件
<?php
$i = 0;
do{
echo '$i = ' . $i . '<br>';
$i++;
}while($i < 10);
?>
$i = 0
$i = 1
$i = 2
$i = 3
$i = 4
$i = 5
$i = 6
$i = 7
$i = 8
$i = 9
<?php
$i = 10;
do{
echo '$i = ' . $i . '<br>';
$i++;
}while($i < 10);
?>
$i = 10
<?php
$array_demo3 = array(
'name' => 'erickson Juang',
'department' => 'EE',
'club' => 'ITAC');
foreach ($array_demo3 as $key => $value) {
echo $key . '=' . $value . '<br>';
}
?>
<?php
$array_demo3 = array(
'name' => 'erickson Juang',
'department' => 'EE',
'club' => 'ITAC');
foreach ($array_demo3 as $key => $value) {
echo $key . '=' . $value . '<br>';
}
?>
Array名稱
<?php
$array_demo3 = array(
'name' => 'erickson Juang',
'department' => 'EE',
'club' => 'ITAC');
foreach ($array_demo3 as $key => $value) {
echo $key . '=' . $value . '<br>';
}
?>
代替index的變數名稱
<?php
$array_demo3 = array(
'name' => 'erickson Juang',
'department' => 'EE',
'club' => 'ITAC');
foreach ($array_demo3 as $key => $value) {
echo $key . '=' . $value . '<br>';
}
?>
代替值的變數名稱
name=erickson Juang
department=EE
club=ITAC
<?php
$array_demo3 = array(
'name' => "erickson Juang",
'department' => 'EE',
'club' => 'ITAC');
foreach ($array_demo3 as $value) {
echo $value . '<br>';
}
?>
erickson Juang
EE
ITAC
$name = 'erickson';
$club = "ITAC";
echo $name . '<br />';
echo $name . ' is member of ' . $club . '<br />';
erickson
erickson is member of ITAC
$name = 'erickson';
$club = "ITAC";
$statement_1 = "$name is member of $club";
$statement_2 = '$name is member of $club';
echo $statement_1 . '<br>';
echo $statement_2 . '<br>';
erickson is member of ITAC
$name is member of $club
<?php
$ans = 1;
for($i = 2; $i < 99; $i++)
$ans *= $i;
echo $ans;
?>
<?php
//php function demo
echo factorial(99);
function factorial($n = 0) {
$ans = 1;
for($i = 1; $i < $n; $i++)
$ans *= $i;
return $ans;
}
?>
用POST 或 GET
<form role="form" method="GET" action="php_demo2.php">
<div>
<label for="Name">Name</label>
<input type="text" id="Name"
name="Name" placeholder="Enter Name">
</div>
<div>
<label for="Email">Email address</label>
<input type="email" id="Email"
name="Email" placeholder="Enter Email">
</div>
<label for="Messages">Message</label>
<textarea rows="5" id="Message"
name="Message" placeholder="Message">
</textarea>
<input style="margin-top:30px;"
type="submit" value="Submit">
</form>
<form role="form" method="GET" action="php_demo2.php">
<div>
<label for="Name">Name</label>
<input type="text" id="Name"
name="Name" placeholder="Enter Name">
</div>
<div>
<label for="Email">Email address</label>
<input type="email" id="Email"
name="Email" placeholder="Enter Email">
</div>
<label for="Messages">Message</label>
<textarea rows="5" id="Message"
name="Message" placeholder="Message">
</textarea>
<input style="margin-top:30px;"
type="submit" value="Submit">
</form>
.
<form role="form" method="GET" action="php_demo2.php">
<div>
<label for="Name">Name</label>
<input type="text" id="Name"
name="Name" placeholder="Enter Name">
</div>
<div>
<label for="Email">Email address</label>
<input type="email" id="Email"
name="Email" placeholder="Enter Email">
</div>
<label for="Messages">Message</label>
<textarea rows="5" id="Message"
name="Message" placeholder="Message">
</textarea>
<input style="margin-top:30px;"
type="submit" value="Submit">
</form>
.
<form role="form" method="GET" action="php_demo2.php">
<div>
<label for="Name">Name</label>
<input type="text" id="Name"
name="Name" placeholder="Enter Name">
</div>
<div>
<label for="Email">Email address</label>
<input type="email" id="Email"
name="Email" placeholder="Enter Email">
</div>
<label for="Messages">Message</label>
<textarea rows="5" id="Message"
name="Message" placeholder="Message">
</textarea>
<input style="margin-top:30px;"
type="submit" value="Submit">
</form>
.
<form role="form" method="GET" action="php_demo2.php">
<div>
<label for="Name">Name</label>
<input type="text" id="Name"
name="Name" placeholder="Enter Name">
</div>
<div>
<label for="Email">Email address</label>
<input type="email" id="Email"
name="Email" placeholder="Enter Email">
</div>
<label for="Messages">Message</label>
<textarea rows="5" id="Message"
name="Message" placeholder="Message">
</textarea>
<input style="margin-top:30px;"
type="submit" value="Submit">
</form>
.
<form role="form" method="GET" action="php_demo2.php">
<div>
<label for="Name">Name</label>
<input type="text" id="Name"
name="Name" placeholder="Enter Name">
</div>
<div>
<label for="Email">Email address</label>
<input type="email" id="Email"
name="Email" placeholder="Enter Email">
</div>
<label for="Messages">Message</label>
<textarea rows="5" id="Message"
name="Message" placeholder="Message">
</textarea>
<input style="margin-top:30px;"
type="submit" value="Submit">
</form>
.
HTTP
REQUEST
REQUEST URL = action = php_demo2.php
<?php
echo "<pre>";
//GET方法
var_dump($_GET);
//POST方法
var_dump($_POST);
echo "</pre>";
?>
array(3) {
["Name"]=>
string(8) "TestName"
["Email"]=>
string(16) "test@address.com"
["Message"]=>
string(15) "My messages"
}
array(0) {
}
int preg_match ( string $pattern,
string $subject
[, array $matches
[, int $flags = 0
[, int $offset = 0 ]]] );
$subject = 'testaabbddaabbcc';
$pattern = '/[a-b]+/';
$result = '';
preg_match($pattern, $subject, $result, 0, 0);
print_r($result);
preg_match($pattern, $subject, $result, PREG_OFFSET_CAPTURE, 0);
print_r($result);
Array
(
[0] => aabb
)
Array
(
[0] => Array
(
[0] => aabb
[1] => 4
)
)
string htmlspecialchars ( string $string
[, int $flags = ENT_COMPAT | ENT_HTML401
[, string $encoding = ini_get("default_charset")
[, bool $double_encode = true ]]] )
string htmlspecialchars ( string $string
[, int $flags = ENT_COMPAT | ENT_HTML401
[, string $encoding = ini_get("default_charset")
[, bool $double_encode = true ]]] )
string htmlspecialchars ( string $string )
(DEMO)
有什麼需要我幫忙的?
幫我去
AA資料庫
找bbb出來
帳號是123
密碼是456
好喔
我要
AA資料庫裡面的bbb
帳號是123
密碼是456
好的
稍等我一下
你要的東西我拿回來了!
$dsn = DatabaseType
.':host=' . Host
. ';dbname='
. DatabaseName;
$dbh = new PDO ($dsn,
DatabaseUser,
DatabasePassword);
define('Host', '127.0.0.1');
define('DatabaseType', 'mysql');
define('DatabaseUser', 'itac_demo');
define('DatabasePassword', 'password');
define('DatabaseName', 'itac_demo');
$dsn = DatabaseType
.':host=' . Host
. ';dbname=' . DatabaseName;
$dbh = new PDO ($dsn,
DatabaseUser,
DatabasePassword);
define('Host', '127.0.0.1');
define('DatabaseType', 'mysql');
define('DatabaseUser', 'itac_demo');
define('DatabasePassword', 'password');
define('DatabaseName', 'itac_demo');
$dsn = DatabaseType
.':host=' . Host
. ';dbname=' . DatabaseName;
$dbh = new PDO ($dsn,
DatabaseUser,
DatabasePassword);
.
.
通常會把藍框框裡面的東西寫在config.php裡面
資料庫帳號
資料庫密碼
資料庫伺服器IP
資料庫名稱
網站名稱
先把命令寫出來
把命令告訴小人
$sql = 'SELECT * FROM `article` WHERE `id` = ?';
$sth = $dbh->prepare($sql);
$sth->execute(array('1'));
讓小人去執行命令(同時把參數放進去)
取得小人所帶回來的資料
$result = $sth->fetch(); //只抓第一筆資料
$result = $sth->fetchAll(); //抓出所有資料
.
決定程式架構
仲介於Model和View
接收User的要求,呼叫對應的Model處理要求,最後回傳給View
最吃設計能力的部份,除了美觀外也要兼顧UX,好的UX是產品成功的第一步,最成功的例子就是Apple。
UX = user experience,使用者經驗,或使用者體驗。
function即是最簡單的Model實作方法,大型程式通常利用物件(Class)的方式來將實作Model。
.
.
.
.
.
接收留言資料,並存入資料庫
回傳留言記錄
其中可以視為Model的部份:
其中可以視為Controller的部份:
.
.
使用者所看到的畫面
.
.
使用者所看到的畫面
操作介面
.
.
使用者所看到的畫面
資料呈現
.
.
.
.
ASP
PHP
Python
Ruby
nodejs
java
.
.
.
以及其他跟使用者介面無關的事情..............
試著研究各種Framework