Một số mã nguồn php đơn giản

Thảo luận trong 'PHP' bắt đầu bởi AmGian, 21 Tháng tám 2009.

  1. Offline

    AmGian

    • Thành viên sáng lập

    Số bài viết:
    392
    Đã được thích:
    231
    Điểm thành tích:
    220
    1. Xuất câu chào:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Bai dau tien</title>
    </head>

    <body>
    <?php
    echo "Chào mừng các bạn đến với ngôn ngữ lập trình php!";
    ?>
    </body>
    </html>

    2. Xuất câu chào nằm trong table và căn giữa:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Ung dung dau tien</title>
    <style type="text/css">
    <!--
    .style2 {color: blue}
    -->
    </style>
    </head>

    <body>
    <?php
    echo "<table width='440' height='32' border='1' align='center' cellpadding='0' cellspacing='0'><tr>";
    echo "<td bgcolor='#999999'><div align='center' class='style2'>";
    echo "Chào mừng các bạn đến với ngôn ngữ lập trình php! <br> Chào mừng các bạn đến với ngôn ngữ lập trình php!";
    echo "</div></td></tr></table>";
    ?>
    </body>
    </html>

    3. Tính cạnh huyền tam giác vuông:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Canh huyen tam giac vuong</title>
    </head>

    <body>
    <?php
    if(isset($_POST["canh_a"]) && isset($_POST["canh_b"])) //kiem tra gia tri da nhap vao hay chua
    {
    $canh_a = $_POST["canh_a"]; //gan gia tri
    $canh_b = $_POST["canh_b"];

    $a2 = pow($canh_a,2);
    $b2 = pow($canh_b,2);

    $tong = $a2 + $b2;
    $canh_huyen = sqrt($tong);
    $canh_huyen = round($canh_huyen,2); //lam tron 2 gia tri
    }
    ?>
    <form id="form1" name="form1" method="post" action="canh_huyen_tam_giac_vuong.php">
    <table width="351" border="1" align="center" cellpadding="2" cellspacing="2">
    <tr>
    <th colspan="2" bgcolor="#99CC00" scope="col">CẠNH HUYỀN TAM GIÁC VUÔNG </th>
    </tr>
    <tr>
    <th width="155" bgcolor="#99FF66" scope="row">Cạnh A </th>
    <td width="176" bgcolor="#99FF66"><label>
    <input name="canh_a" type="text" id="canh_a" value="<?php echo $_POST["canh_a"];?>" />
    </label></td>
    </tr>
    <tr>
    <th bgcolor="#99FF66" scope="row">Cạnh B </th>
    <td bgcolor="#99FF66"><label>
    <input name="canh_b" type="text" id="canh_b" value="<?php echo $_POST["canh_b"];?>" />
    </label></td>
    </tr>
    <tr>
    <th bgcolor="#99FF66" scope="row">Cạnh Huyền </th>
    <td bgcolor="#99FF66"><label>
    <input name="canh_huyen" type="text" id="canh_huyen" value="<?php echo $canh_huyen;?>" readonly="true" style="background-color:#99CC00" />
    </label></td>
    </tr>
    <tr>
    <th colspan="2" bgcolor="#99CC00" scope="row"><label>
    <input type="submit" name="Submit" value="TÍNH" />
    </label></th>
    </tr>
    </table>
    </form>
    </body>
    </html>

    4. Xuất câu chào nếu nhập giờ
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Chao theo ngay</title>
    </head>

    <body>
    <form id="form1" name="form1" method="post" action="">
    <table width="257" border="1" align="center" cellpadding="2" cellspacing="2" bgcolor="#99FF99">
    <tr>
    <th colspan="2" bgcolor="#99CC00" scope="col">CHÀO THEO GIỜ </th>
    </tr>
    <tr>
    <th width="98" scope="row">Nhập Giờ </th>
    <td width="139"><label>
    <input name="gio" type="text" id="gio" value="<?php echo $_POST["gio"];?>" size="10" />
    (Giờ)
    </label></td>
    </tr>
    <tr>
    <th colspan="2" bgcolor="#99CC00" scope="row">
    <?php
    if(isset($_POST["gio"]))
    {
    $gio = $_POST["gio"];
    if($gio > 0 && $gio < 13)
    $cauchao = "Chào buổi sáng!";
    elseif($gio >= 13 && $gio <= 18)
    $cauchao = "Chào buổi chiều!";
    elseif($gio > 18 && $gio <= 24)
    $cauchao = "Chào buổi tối!";
    else
    $cauchao = "Xin Lỗi, Bạn nhập sai rồi!";
    echo $cauchao;
    }
    ?>
    </th>
    </tr>
    <tr>
    <th colspan="2" bgcolor="#99CC00" scope="row"><label>
    <input type="submit" name="Submit" value="CHÀO" />
    </label></th>
    </tr>
    </table>
    </form>
    </body>
    </html>

    5. In lời chào:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>In Loi Chao</title>
    <style type="text/css">
    <!--
    .style1 {
    font-size: 24px;
    font-weight: bold;
    color: #FFFFFF;
    }
    -->
    </style>
    </head>

    <body>
    <?php
    if(isset($_POST["ten"]))
    {
    $ten=$_POST["ten"];
    $cau_chao="Chào Bạn ".$ten;
    }
    ?>
    <form id="form1" name="form1" method="post" action="">
    <table width="303" border="1" align="center" cellpadding="1" cellspacing="1" bgcolor="#00FFFF">
    <tr>
    <td width="295" bgcolor="#0066FF"><div align="center" class="style1">IN LỜI CHÀO </div></td>
    </tr>
    <tr>
    <td><div align="center">Họ Tên Bạn
    <label>
    <input name="ten" type="text" id="ten" value="<?php echo $ten;?>" />
    </label>
    </div></td>
    </tr>
    <tr>
    <td align="center"><label><?php echo $cau_chao;?></label>&nbsp;</td>
    </tr>
    <tr>
    <td align="center"><label>
    <input type="submit" name="Submit" value="Chào!" />
    </label></td>
    </tr>
    </table>
    </form>
    </body>
    </html>


    6. Định dạng màu chữ màu nền:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Dinh dang mau chu mau nen</title>
    <style type="text/css">
    <!--
    .style1 {
    color: #FFFFFF;
    font-weight: bold;
    font-size: 24px;
    }
    -->
    </style>
    </head>

    <body>
    <form id="form1" name="form1" method="post" action="dinh_dang_mau_chu_mau_nen.php">
    <table width="427" border="1" align="center" cellpadding="2" cellspacing="2" bgcolor="#999933">
    <tr>
    <th colspan="2" bgcolor="#666600" scope="col"><span class="style1">ĐỊNH DẠNG MÀU CHỮ_MÀU NỀN </span></th>
    </tr>
    <tr>
    <th width="135" scope="row">Nội Dung </th>
    <td width="272"><label>
    <input name="noi_dung" type="text" id="noi_dung" value="<?php echo $_POST["noi_dung"];?>" size="40" />
    </label></td>
    </tr>
    <tr>
    <th scope="row">Màu Chữ </th>
    <td><label>
    <input name="mau_chu" type="text" id="mau_chu" value="<?php echo $_POST["mau_chu"];?>" size="20" />
    </label></td>
    </tr>
    <tr>
    <th scope="row">Màu Nền </th>
    <td><label>
    <input name="mau_nen" type="text" id="mau_nen" value="<?php echo $_POST["mau_nen"];?>" size="20" />
    </label></td>
    </tr>
    <tr>
    <th colspan="2" scope="row"><label>
    <input type="submit" name="Submit" value="XEM KẾT QUẢ" />
    </label></th>
    </tr>
    </table>
    </form>
    <?php
    $mau_chu = $_POST["mau_chu"];
    $mau_nen = $_POST["mau_nen"];
    $noi_dung = $_POST["noi_dung"];
    ?>
    <table width="432" border="1" align="center" cellpadding="2" cellspacing="2" bgcolor="#<?php echo $mau_nen;?>">
    <tr>
    <th scope="col"><font color="#<?php echo $mau_chu;?>"><?php echo $noi_dung;?></font></th>
    </tr>
    </table>
    </body>
    </html>

    :yyc21:

Chia sẻ trang này

Advertising: Linux system admin | nukeviet | nukeviet 4 | Upload ảnh miễn phí