PHP小技巧

字號(hào):


    PHP批量取得checkbox的值
    1、命名
    <input type=’checkbox’ name=’checkbox[]’ value=dwmyrow[banzhu] />
    2、使用
    當(dāng)計(jì)劃當(dāng)作sql指令的一部分時(shí):如果參與控制的字段是數(shù)值型的,則
    if(! empty(_POST[’checkbox’])) {
    expr = join(",", _POST[’checkbox’]);
    sql = "select * from tbl_name where field in (expr)";
    }
    如果參與控制的字段是數(shù)值型的,則
    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=="提交")
    {
    //執(zhí)行表單操作
    }
    else
    {
    //讀取默認(rèn)值
    }
    PHP 獲取字符串長(zhǎng)度
    strlen(myrow[1])
    PHP Url轉(zhuǎn)向
    Header("Location: "._SERVER["HTTP_REFERER"]);
    PHP超全局對(duì)象
    <?php
    a = 1;
    b = 2;
    function Sum()
    {
    GLOBALS["b"] = GLOBALS["a"] + GLOBALS["b"];
    }
    Sum();
    echo b;
    ?>
    PHP 表單取值
    如果 mothod="get" 就用 _GET["test"] 代替test
    如果 mothod="post" 就用 _POST["test"] 代替test
    PHP取得當(dāng)前IP
    <?=HTTP_SERVER_VARS["REMOTE_ADDR"]?>
    PHP 取得當(dāng)前時(shí)間
    <?php
    echo date("Y-m-d G:i:s");
    ?>
    date("Y年m月d日")
    Date ("Y-n-j")
    <script type="text/javascript"> document.body.oncopy = function () { setTimeout( function () { var text = clipboardData.getData("text"); if (text) { text = text + "濟(jì)南網(wǎng)站建設(shè) - 原文鏈接:"+location.href; clipboardData.setData("text", text); } }, 100 ) } </script>