One, several input functions in PHP echo, print (), Print_r (), printf (), sprintf (), Var_dump () the difference.
1.echo: Is a statement is not a function, there is no return value, you can output multiple variable values, no parentheses are required. Cannot output arrays and objects, only simple types (such as int,string) can be printed;
2.print: Is the statement is not a function, has a return value of 1, can only output a variable, do not need parentheses, can not output arrays and objects, can only print simple types (such as int,string);
3.print_r (): is a function that can print a composite type (such as String, int, float, array, object, etc.) when the output array is represented by a struct, and can be Print_r ($STR, true) to make the Print_r () Returns the value of Print_r processing without outputting;
4.PRINTF (): Is the function to format the text after the output, reference C language
5.SPRINTF (): Is a function, similar to printf (), but does not print, but instead returns formatted text (the function writes a formatted string to a variable instead of outputting it) the other is the same as printf;
6.var_dump (): is a function that outputs the contents, type, or length of a variable's content, type, or string.
Second, the use of the session to disable cookies, set the session expiration method, corresponding function:
1. Through the URL value, the session ID attached to the URL (disadvantage: The entire site can not have a pure static page, because the pure static page session ID will not be able to continue to pass to the next page);
2. By hiding the form, place the session ID in the form's hidden text box and submit it in the past (disadvantage: the case of non-form that does not apply to the direct jump of <a> tag);
3. Configure the php.ini file directly, set the SESSION.USE.TRANS.SID = 0 in the php.ini file to 1;
4. Save the session ID in the form of file, database, etc., and call it manually during the cross-page process;
1.setCookie (Session_name (), session_id (), Time () +60, "/");
2.session_set_cookie_params;(to deposit the session into a cookie);
Note: The Session.gc_probability/session.gc_divisor in php.ini
Third, PHP gets the file content method, corresponding function
1.file_get_contents () Gets the contents of the file (which can be obtained with the Get and post methods), and the entire file is read into a string;
2. Open the URL with fopen () and get the content in get (with the help of the fgets () function);
3. Use the Fsockopen function to open the URL (can be obtained as Get and post) to get the complete data including header and body in Get mode;
4. Use the Curl Library to get the content, before using the Curl Library, you need to review the php.ini to see if the curl extension is turned on
Iv. differences between Isset (), Empty () and Is_null
1, when the variable is not defined, is_null () and "parameter itself" is not allowed as a parameter to judge, will be reported notice warning error;
2, Empty,isset first checks whether the variable exists, and then the value of the variable is detected. The Is_null and "parameter itself" simply check the value of the variable directly, whether it is null, so if the variable is undefined, an error will occur!
3, Isset (): Returns false only if null and undefined;
4, Empty (): "", 0, "0", NULL, FALSE, Array (), Undefined, all return FALSE;
5, Is_null (): only to determine whether it is null, not defined report warning;
6, the variable itself as a parameter, and empty () consistent, but accept the undefined variable, reported warning;
The role and Difference of strlen () and Mb_strlen
In PHP, strlen and Mb_strlen are functions that seek the length of a string.
PHP built-in string length function strlen cannot handle Chinese strings correctly, it only gets the number of bytes that the string occupies. For the Chinese encoding of GB2312, the value of strlen is twice times the number of Chinese characters, and for UTF-8 encoded Chinese, is 3 times times (in UTF-8 encoding, a Chinese character accounted for 3 bytes). Using Mb_strlen function can solve this problem well. The usage of Mb_strlen is similar to strlen, except that it has a second optional parameter for specifying character encoding. For example get UTF-8 string $str length, can be used Mb_strlen ($str, ' UTF-8 '). If you omit the second argument, the internal encoding of PHP is used. The internal code can be obtained through the mb_internal_encoding () function. It is important to note that Mb_strlen is not a PHP core function and needs to be sure that the Php_mbstring.dll is loaded in the php.ini before use, that is, to ensure that the "Extension=php_mbstring.dll" line is present and not commented out. Otherwise, there is an issue with undefined functions. Vi. how PHP obtains the IP address of the client
$_server[' REMOTE_ADDR ']; Using a global array to obtain
getenv (' remote_addr '); Using environment variables to obtain
When a client uses a proxy, it does not get a real IP address
PHP Basic Questions