PHP is a server-side scripting language for creating dynamic Web pages. Like ASP and ColdFusion, users can mix PHP and HTML to write Web pages, and when a visitor browses to the page, the server first processes the PHP commands in the page and then delivers the processed results along with the HTML content to the browser on the access side. But unlike ASP or ColdFusion, PHP is a source-code-open program with good cross-platform compatibility. Users can run PHP on Windows NT systems and many versions of UNIX systems, and can run PHP as a built-in module or CGI program for Apache servers. This article summarizes 8 tips that are commonly used in PHP's daily development.
PHP Batch Gets the value of the checkbox
1, naming
Copy Code code as follows:
<input type= ' checkbox ' name= ' checkbox[] ' value= $dwmyrow [Banzhu]/>
2. Use
When the plan is treated as part of the SQL directive: if the field that participates in the control is numeric, the
Copy Code code as follows:
if (! empty ($_post[' checkbox ')) {
$expr = Join (",", $_post[' checkbox '));
$sql = "SELECT * from Tbl_name where field in ($expr)";
}
If the field participating in the control is numeric, the
Copy Code code as follows:
if (! empty ($_post[' checkbox ')) {
$expr = "'". Join ("', '", $_post[' checkbox ']). ".";
$sql = "SELECT * from Tbl_name where field in ($expr)";
}
3, PHP to determine whether form forms submitted
Copy Code code as follows:
$action = $HTTP _post_vars["Button1"];
if ($action = = "Submit")
{
To perform a form operation
}
Else
{
Reading default values
}
4, PHP get string length
Copy Code code as follows:
PHP URL Turn
Copy Code code as follows:
Header ("Location:". $_server["Http_referer"]);
5, PHP Super Global object
Copy Code code as follows:
<?php
$a = 1;
$b = 2;
function Sum ()
{
$GLOBALS ["b"] = $GLOBALS ["a"] + $GLOBALS ["B"];
}
Sum ();
Echo $b;
?>
6, PHP form to take the value
If mothod= "get" replaces $test with $_get["test"
If mothod= "POST", replace $test with $_post["test"
7, PHP to obtain the current IP
Copy Code code as follows:
<?= $HTTP _server_vars["REMOTE_ADDR"]?>
8, PHP to obtain the current time
Copy Code code as follows:
<?php
echo Date ("y-m-d g:i:s");
?>
Date ("Y year M month D Day")
Date ("Y-n-j")