PHP 常見郁悶問題答解
更新時間:2006年11月25日 00:00:00 作者:
PHP 常見郁悶問題答解
轉(zhuǎn)自喜悅村
在PHP4.2以后的版本中register_global默認(rèn)為off
若想取得從另一頁面提交的變量:
方法一:在PHP.ini中找到register_global,并把它設(shè)置為on.
方法二:在接收網(wǎng)頁最前面放上這個extract($_POST);extract($_GET);(注意extract($_SESSION)前必須要有Session_Start()).
方法三:一個一個讀取變量$a=$_GET["a"];$b=$_POST["b"]等,這種方法雖然麻煩,但比較安全.
PHP代碼:
<?PHP
Ob_Start();
Session_Start();
Echo "<pre>";
Echo "本頁得到的_GET變量有:";
Print_R($_GET);
Echo "本頁得到的_POST變量有:";
Print_R($_POST);
Echo "本頁得到的_COOKIE變量有:";
Print_R($_COOKIE);
Echo "本頁得到的_SESSION變量有:";
Print_R($_SESSION);
Echo "</pre>";
?>
為什么我向另一網(wǎng)頁傳送變量時,只得到前半部分,以空格開頭的則全部丟失
PHP代碼:--------------------------------------------------------------------------------
<?php
$Var="hello php";//修改為$Var=" hello php";試試得到什么結(jié)果
$post= "receive.php?Name=".$Var;
header("location:$post");
?>
--------------------------------------------------------------------------------
receive.php的內(nèi)容:
PHP代碼:--------------------------------------------------------------------------------
<?PHP
Echo "<pre>";
Echo $_GET["Name"];
Echo "</pre>";
?>
--------------------------------------------------------------------------------
正確的方法是:
PHP代碼:--------------------------------------------------------------------------------
<?php
$Var="hello php";
$post= "receive.php?Name=".urlencode($Var);
header("location:$post");
?>
--------------------------------------------------------------------------------
在接收頁面你不需要使用Urldecode(),變量會自動編碼.
規(guī)范你的SQL語句
在表格,字段前面加上"`",這樣就不會因為誤用關(guān)鍵字而出現(xiàn)錯誤,
當(dāng)然我并不推薦你使用關(guān)鍵字.
例如
$Sql="INSERT INTO `xltxlm` (`author`, `title`, `id`, `content`, `date`) VALUES ('xltxlm', 'use`', 1, 'criterion your sql string ', '2003-07-11 00:00:00')"
我怎么知道系統(tǒng)默認(rèn)支持什么函數(shù)
PHP代碼:
--------------------------------------------------------------------------------
<?php
$arr = get_defined_functions();
Function php() {
}
echo "<pre>";
Echo "這里顯示系統(tǒng)所支持的所有函數(shù),和自定以函數(shù)php\n";
print_r($arr);
echo "</pre>";
?>
如何比較兩個日期相差幾天
PHP代碼:
--------------------------------------------------------------------------------
<?PHP
$Date_1="2003-7-15";//也可以是:$Date_1="2003-6-25 23:29:14";
$Date_2="1982-10-1";
$Date_List_1=explode("-",$Date_1);
$Date_List_2=explode("-",$Date_2);
$d1=mktime(0,0,0,$Date_List_1[1],$Date_List_1[2],$Date_List_1[0]);
$d2=mktime(0,0,0,$Date_List_2[1],$Date_List_2[2],$Date_List_2[0]);
$Days=round(($d1-$d2)/3600/24);
Echo "偶已經(jīng)奮斗了 $Days 天^_^";
?>
數(shù)據(jù)放入數(shù)據(jù)庫和取出來顯示在頁面需要注意什么
入庫時
$str=addslashes($str);
$sql="insert into `tab` (`content`) values('$str')";
出庫時
$str=stripslashes($str);
顯示時
$str=htmlspecialchars(nl2br($str)) ;
轉(zhuǎn)自喜悅村
在PHP4.2以后的版本中register_global默認(rèn)為off
若想取得從另一頁面提交的變量:
方法一:在PHP.ini中找到register_global,并把它設(shè)置為on.
方法二:在接收網(wǎng)頁最前面放上這個extract($_POST);extract($_GET);(注意extract($_SESSION)前必須要有Session_Start()).
方法三:一個一個讀取變量$a=$_GET["a"];$b=$_POST["b"]等,這種方法雖然麻煩,但比較安全.
PHP代碼:
<?PHP
Ob_Start();
Session_Start();
Echo "<pre>";
Echo "本頁得到的_GET變量有:";
Print_R($_GET);
Echo "本頁得到的_POST變量有:";
Print_R($_POST);
Echo "本頁得到的_COOKIE變量有:";
Print_R($_COOKIE);
Echo "本頁得到的_SESSION變量有:";
Print_R($_SESSION);
Echo "</pre>";
?>
為什么我向另一網(wǎng)頁傳送變量時,只得到前半部分,以空格開頭的則全部丟失
PHP代碼:--------------------------------------------------------------------------------
<?php
$Var="hello php";//修改為$Var=" hello php";試試得到什么結(jié)果
$post= "receive.php?Name=".$Var;
header("location:$post");
?>
--------------------------------------------------------------------------------
receive.php的內(nèi)容:
PHP代碼:--------------------------------------------------------------------------------
<?PHP
Echo "<pre>";
Echo $_GET["Name"];
Echo "</pre>";
?>
--------------------------------------------------------------------------------
正確的方法是:
PHP代碼:--------------------------------------------------------------------------------
<?php
$Var="hello php";
$post= "receive.php?Name=".urlencode($Var);
header("location:$post");
?>
--------------------------------------------------------------------------------
在接收頁面你不需要使用Urldecode(),變量會自動編碼.
規(guī)范你的SQL語句
在表格,字段前面加上"`",這樣就不會因為誤用關(guān)鍵字而出現(xiàn)錯誤,
當(dāng)然我并不推薦你使用關(guān)鍵字.
例如
$Sql="INSERT INTO `xltxlm` (`author`, `title`, `id`, `content`, `date`) VALUES ('xltxlm', 'use`', 1, 'criterion your sql string ', '2003-07-11 00:00:00')"
我怎么知道系統(tǒng)默認(rèn)支持什么函數(shù)
PHP代碼:
--------------------------------------------------------------------------------
<?php
$arr = get_defined_functions();
Function php() {
}
echo "<pre>";
Echo "這里顯示系統(tǒng)所支持的所有函數(shù),和自定以函數(shù)php\n";
print_r($arr);
echo "</pre>";
?>
如何比較兩個日期相差幾天
PHP代碼:
--------------------------------------------------------------------------------
<?PHP
$Date_1="2003-7-15";//也可以是:$Date_1="2003-6-25 23:29:14";
$Date_2="1982-10-1";
$Date_List_1=explode("-",$Date_1);
$Date_List_2=explode("-",$Date_2);
$d1=mktime(0,0,0,$Date_List_1[1],$Date_List_1[2],$Date_List_1[0]);
$d2=mktime(0,0,0,$Date_List_2[1],$Date_List_2[2],$Date_List_2[0]);
$Days=round(($d1-$d2)/3600/24);
Echo "偶已經(jīng)奮斗了 $Days 天^_^";
?>
數(shù)據(jù)放入數(shù)據(jù)庫和取出來顯示在頁面需要注意什么
入庫時
$str=addslashes($str);
$sql="insert into `tab` (`content`) values('$str')";
出庫時
$str=stripslashes($str);
顯示時
$str=htmlspecialchars(nl2br($str)) ;
相關(guān)文章
關(guān)于php操作mysql執(zhí)行數(shù)據(jù)庫查詢的一些常用操作匯總
本篇文章是對關(guān)于php操作mysql執(zhí)行數(shù)據(jù)庫查詢的一些常用操作進(jìn)行了詳細(xì)的匯總介紹,需要的朋友參考下2013-06-06