Php 簡介

Php 簡介


#php不同環境下的安裝

http://php.net/manual/zh/install.php


#php標準語法

<!doctype html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
<body>
    <?php echo "Hello , world"; ?>
</body>
</html>


#組態頁

<?php phpinfo(); ?>


#表單

資料庫存取表單值主要透過
$_POST
$_GET
確認在處理網頁時
php.ini的REGISTER_GLOBALS 設定時必須是關閉的

<!doctype html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>Personalized Greeting Form</title>
    </head>
<body>
    <?php if(!empty($_POST['name'])){
        echo "Greetings, {$_POST['name']}, and welcome.";} ?>

    <form action="<?php echo $_SERVER['PHP_HELP'];?>" method="post">
    Enter your name :<input type="text" name="name" />
    <input type="submit"> />
    </form>

</body>
</html>


#資料庫

php支援所有主流資料庫
MySQL
PostgreSQL
Oracle
Sybase
SQLite

You could take the library.sql file
by http://example.oreilly.com/0636920012443

<?php 

$db = new mysqli("localhost", "petermac", "password", "library");

//確保OS中有正確的憑證
if ($db->connnect_error){
    die("Connect Error({$db->connect_errno}) {$db->connect_error}");
    }

?>

<html>
    <head>
    </head>
<body>
    <table cellSpacing="2" cellPadding="6" align="center" border="1">
    <tr>
        <td colspan="4">
            <h3 align="center">These Books are currently available</h3>
        </td>
    </tr>

    <tr>
        <td align="center">Title</td>
        <td align="center">Year Published</td>
        <td align="center">ISBN</td>
    </tr>
    /*
    mysql_fetch_assoc() 函数從结果集中取得一行作为關聯数组。

傳回根據從結果集合取得的行生成的關聯術組,如果沒有更多行,則返回false。如果沒有返回根據定義assoc() 函数就返回false
    */

    <?php while ($row = $result->fetch_assoc()){ ?>
        <tr>
            <td><?php echo stripslashes($row['title']); ?></td>
            <td> align="center"><?php echo $row['pub_year']; ?><td>
            <td><?php echo $row['ISBN']; ?></td>
        </tr>
        <?php } ?>
</table>

</body>
</html>


#圖像

利用GD延伸函式庫
<?php 
if (isset($_GET['meeage'])) {

$font  = "items" ;
$size  = 12;
$image= imagecreatefrompng("button,png");
$tsize	= imagettfbox($size, 0, $font, $_GET['message'] );

$dx = abs( $tsize[2] - $tsize[0]);
$dy = abs( $tsize[5] - $tsize[3]);
$x	 = (imagex($image) - $dx) /2;
$y = (imagey/($image) - $dy)/2 + $dy;

//繪製文字

$black = imagecolorallocate($im,0,0,0);
imagettftext($image, $size, 0, $x, $y, $block, $font, $_GET['message']);

//回傳文字
header("Content-type: image/png");
imagepng($image);

exit;
} ?>

<html>
    <head>
        <title>Button Form</title>
    </head>

    <body>
        <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="GET">
        Enter message to appear on button:
        <input type="text" name="message" /><br />
        <input type="submit" value="Create Button" />
        </form>
    </body>
</html>

Comments

Popular posts from this blog

MEGA 暫存檔案刪除

IOS GCD多執行緒

利用CMD指令強制刪除