String
- Gets the length of the string: strlen () function
Get Chinese text long echo mb_strlen ($str, "UTF8");
English string interception
$str='i love you';
Capture the letters of love
Echo substr ($str, 2, 4);//Why the starting position is 2, because the SUBSTR function calculates that the string position is starting from 0, that is, the position of 0 is the space where the i,1 is, and the position of L is 2. Starting from position 2, take 4 characters, that is love
Chinese string interception
Mb_substr ();
- String Lookup
Strpos (string to be processed, string to position, starting position of position [optional])
- Replace string
Str_replace (The string to find, the string to replace, the string to be searched, and the replacement to count [optional])
formatting strings
$str'99.9';
$resultsprintf('%01.2f'$str);
echo $result;//Results show 99.90
Merging strings
$arrarray('Hello''World!');$result = implode(''$arr);print_r($result);//结果显示Hello World!
Split string
`$str` = 'apple,banana';`$result` = explode(',', $str);print_r($result);//结果显示array('apple','banana')
String escape function Addslashes ()
Function Description: Used to add an escape character to a special character , returns a string
Return value: An escaped string
Example:
$str
= "What ' s your name?";
echo addslashes ($STR);//output: what\ ' s your name
-
Cookie
- Common parameters
Name (cookie name) can be accessed via $_cookie[' name ']
value (value of cookie)
Expire (Expiration time) UNIX timestamp format, default is 0, indicating that the browser is off or dead
Path (valid path) if the path is set to '/', the entire site is valid
domain (valid domain) the default entire domain name is valid, if ' www ' is set. Imooc.com ', the
2 is valid only in the WWW subdomain.
There is also a function in PHP that sets a cookie Setrawcookie,setrawcookie is basically the same as Setcookie, the only difference is that value values are not automatically urlencode. So when needed, manually urlencode
- Delete and set expiration
Setcookie (' Test ', ', Time ()-1);
- Valid path
Setcookie (' Test ', Time (), 0, '/path '),//Set the path and its subdirectories are valid
- Session
- Using the session in PHP is very simple, first executing the Session_Start method to open the session, and then through the global variable $_session session read and write.
session_start();
$_SESSION['test'] = time();
var_dump($_SESSION);
- The session automatically encode and decode the values to be set, so the session can support any data type, including data and objects.
- Delete
Deleting a session value can use PHP's unset function, which is removed from the global variable $_session and cannot be accessed
session_start();
$_SESSION['name'] = 'jobs';
unset($_SESSION['name']);
echo $_SESSION['name']; //提示name不存在
If you want to delete all sessions, you can use the Session_destroy function to destroy the current Session,session_destroy delete all data, but session_id still exists
Session_destroy does not immediately destroy the values in global variables , it $_SESSION
is only empty the next time they are accessed, $_SESSION
so if you need to destroy $_session immediately, you can use the unset function.
If it is necessary to destroy the session_id in the cookie at the same time, usually when the user exits, you also need to explicitly call the Setcookie method to delete the session_id cookie value.
'). addclass (' pre-numbering '). Hide (); $ (this). addclass (' has-numbering '). Parent (). append ($numbering); for (i = 1; i <= lines; i++) {$numbering. Append ($ ('
'). Text (i)); }; $numbering. FadeIn (1700); }); });
The above describes the PHP entry string, cookie,session, including special characters, global variables, and I hope that the PHP tutorial interested in a friend helpful.