Instance 11: Date Stamp, date display
Copy Code code as follows:
<?php
echo time ();//Returns a string of timestamp in seconds
echo "<br>";
echo Date ("Y-m-d h:i:s", Time () +8*3600),//formatting times, +8*3600 changed to China time zone
echo "<br>";
$str = "2010-08-24 10:26:10";
echo Date ("Y-m-d h:i:s", Strtotime ($STR));//strtotime Convert a string to a timestamp
echo "<br>";
?>
Example 12: Form variable encoding, receiving
Copy Code code as follows:
<?php
echo $str =urlencode ("first page");//url variable code, like Google
echo "<br>". UrlDecode ($STR);//url variable decoding, I see it.
echo "<br><a href=index.php?page=". $str. " > First page </a> ";
echo "<br>";
The IF ($_get) echo "variable is received:". $_get[' page '];//$_get corresponds to $_post,php is automatically recognized URL encoding and automatically decoded well.
echo "<br>";
?>
Instance 13:session use
Copy Code code as follows:
<?php
Session_Start ();//session expires immediately after the browser is closed, so you need to declare it to read and write session
$_session[' id ']= ' server ';//This is the declaration and initialization, the same as the array usage
$_session[' name ']= ' Session ';
Print_r ($_session);//Session registration successfully outputs an array
echo "<br>";
$_session[' id ']= ' or server ';//change a session, then output see
unset ($_session[' name ');/logoff a session, then output look
Print_r ($_session);
echo "<br>";
?>
Instance 14:cookie use
Copy Code code as follows:
<?php
Setcookie ("id", "client");//This is the function that declares and initializes the cookie. Shutdown Browser is invalid
Setcookie ("name", "Session", Time () +3600);//Expires 1 hours from this
Print_r ($_cookie)//Session registration successfully outputs an array, or it can be accessed using $http_cookie_vars
echo "<br>";
Setcookie ("id", "or client");/change a session, then output see
unset ($_cookie[' name ');/Log off a session, and then output a look, equivalent to Setcookie ("name", "", Time ()-1); This is a lot of books said, in fact, with unset can also be written off
Print_r ($_cookie);
echo "<br>";
?>