PHP 动态网站开发中常用的 8 个小技巧
本文总结了 PHP 日常开发中常用的 8
个小技巧。 PHP 批最取得 checkbox 的值
1、命名
<input type='checkbox' name='checkbox[]' value=$dwmyrow[banzhu] />
2、使用
当计划当作 sql 指令的一部分时:如果参与控制的字段是数值型的,则
if(! empty($_POST['checkbox'])) {
$expr = join(",", $_POST['checkbox']);
$sql = "select * from tbl_name where field in ($expr)";
}
如果参与控制的字段是数值型的,则
if(! empty($_POST['checkbox'])) {
$expr = "'".join("','", $_POST['checkbox']).".";
$sql = "select * from tbl_name where field in ($expr)";
}
PHP 判断 Form 表单是否提交
$action=$HTTP_POST_VARS["Button1"];
if($action=="提交")
{
//执行表单操作
}
else
{
//读取默认值
}
PHP 获取字符串长度
strlen($myrow[1])
PHP Url 转向
Header("Location: ".$_SERVER["HTTP_REFERER"]);
PHP 超全局对象
<?
$a = 1;
$b = 2;
function Sum()
{
$GLOBALS["b"] = $GLOBALS["a"] + $GLOBALS["b"];
}
Sum();
echo $b;
?>
PHP 表单取值
如果 mothod="get"
就用 $_GET["test"] 代替$test