Tài liệu PHP & MySQL Discussion part 4 - Pdf 87

Thủ thuật php

Sử dụng PHP để chuyển đến 1 URL khác

PHP
Code:
<?php
header("Location:
?> Trong HTML bạn có thể sử dụng đoạn mã sau: Code:
<html>
<head>
<title>Please wait...</title>
<script language="JavaScript">
self.location.href='
</script>
</head>
<body>
</body>
</html>

Hiển thị thông tin trình duyệt đang sử dụng.

Bạn sử dụng đoạn PHP sau trong đoạn mà bạn muốn hiển thị:

PHP

PHP Code:
<?
$dbuser=""; //Database Username
$dbname=""; //Database Name
$dbpass=""; // Database Password
?>

B3:Tạo 1 file tag.php có nôi dung như sau:
PHP Code:
<iframe src="view.php" name="tag" width="179" height="130" frameborder=0 ma
rginwidth="0" marginheight="0"></iframe><form method="POST" ACTION="tod
o.php">
<input type="text" NAME="name" Value=">">
<textarea NAME="post" cols="27" rows="3"></textarea>
<br>
<input TYPE="submit" value="Submit">
B4:Tiếp theo là file todo.php
PHP Code:
<?php
if ($name == '' || $post == ''")
{
die ("Please fill all fields. Click <a HREF=tag.php>here</a> to return.");
}
include('config.php');

$post = preg_replace("/</","&lt;",$post);
$post = preg_replace("/>/","&gt;",$post);

$comments=$place["comments"];
//là nơi hiển thị trên trang web
?>
»<b><? echo "$place[name]"; ?></b><? echo ": $comments<br>" ; ?>
<?
}?>

Chúc bạn thành công !

Ngày 1: Những câu lệnh cơ bản xử lí chuỗi
Code:
<?
//Hàm kiem tra mot chuoi có phai là mot hyperlink:

function checkLink($link){
* *if (!stristr($link, "http://")) return "http://".$link;
* *else return $link;
*}

//Hàm cat bo khong trong trong chuoi:

function stripSpaces($text, $replace=NULL) {
* *if (is_string($replace)) return str_replace(" ", substr($replace, 0, 1), $text);
* *else return str_replace(" ", "", $text);
*}

//Hàm kiem tra mot chuoi có phai là các ky tu alphabet hoac ky tu so tu 0-9

function alphaNum($stripper) {
* *return preg_replace("/[^a-zA-Z0-9]/", "", $stripper);


* *$search = array("/</", "/>/");
* *$replace = array('&#x003c;', '&#x003e;');

* *return preg_replace($search, $replace, $text);
*}

//Hàm *kiem tra bay loi các dang chuoi nhap vào (form nhap) *nhu email,number,file,...

function isValidInput($userEntry, $type=NULL) {
* *if (empty($userEntry) || !is_string($userEntry)) return FALSE;

* *switch ($type) {
* *case "chars_space":
*if (eregi("^[a-z_0-9 ]+$",$userEntry)) return TRUE;
*else return FALSE;
*break;

* *case "number":
*if (ereg("^[0-9]+$",$userEntry)) return TRUE;
*else return FALSE;
*break;


Nhờ tải bản gốc
Music ♫

Copyright: Tài liệu đại học © DMCA.com Protection Status