1. The differences between several input functions echo, print(), print_r(), printf(), sprintf(), var_dump() in PHP.
1.echo: It is a statement, not a function. It has no return value and can output multiple variable values without parentheses. Arrays and objects cannot be output, only simple types (such as int, string) can be printed;
2.print: It is a statement, not a function. It has a return value of 1. It can only output one variable. It does not necessarily require parentheses. It cannot output arrays and objects. It can only print simple types (such as int, string);
3.print_r(): It is a function that can print composite types (such as string, int, float, array, object, etc.) when outputting the array, it will be represented by a structure, and print_r can be used through print_r($str,true) ()Does not output but returns the value processed by print_r;
4.printf(): It is a function that formats text and outputs it. Please refer to C language
5.sprintf(): It is a function, similar to printf(), but does not print, but returns formatted text (this function writes the formatted string into a variable instead of outputting it) Others Same as printf;
6.var_dump(): It is a function that outputs the content and type of a variable or the content, type, and length of a string.
2. How to use a session that disables cookies, and set the session expiration method and corresponding function:
1. Pass the value through the url and append the session id to the url (disadvantage: there cannot be purely static pages in the entire site, because the purely static page session id will not be passed to the next page);
2. By hiding the form, put the session id in the hidden text box of the form and submit it together with the form (disadvantage: it is not applicable to non-form situations where the tag directly jumps);
3. Configure the php.ini file directly, and set session.use.trans.sid = 0 in the php.ini file to 1;
4. Save the session ID in a 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(60);(Save session in cookie);
Note: session.gc_probability / session.gc_divisor in php.ini
3. PHP method of obtaining file content, corresponding function
1.file_get_contents() Get the contents of the file (can be obtained with the get and post methods), and read the entire file into a string;
2. Use fopen() to open the url and obtain the content by get method (with the help of fgets() function);
3. Use the fsockopen function to open the url (can be obtained by get and post methods) and obtain the complete data by get method, including header and body;
4. Use the curl library to obtain content. Before using the curl library, you need to check php.ini to see if the curl extension has been turned on
4. The difference between isset(), empty() and is_null
1. When the variable is undefined, is_null() and "the parameter itself" are not allowed to be judged as parameters, and a Notice warning error will be reported;
2. Empty and isset will first check whether the variable exists, and then detect the variable value. And is_null and "the parameter itself" just check the variable value directly to see if it is null, so if the variable is not defined, an error will occur!
3. isset(): Only when null and undefined, returns false;
4. empty(): "", 0, "0", NULL, FALSE, array(), undefined, all return false;
5. is_null(): only determines whether it is null, and will report a warning if it is not defined;
6. The variable itself is used as a parameter, which is consistent with empty(), but when accepting undefined variables, a warning will be reported;
5. The functions and differences between strlen() and mb_strlen
In PHP, strlen and mb_strlen are functions to find the length of a string
$_SERVER['REMOTE_ADDR'] ; Obtained through global array
getenv('REMOTE_ADDR') ; Get
through environment variablesWhen the client uses a proxy, it cannot obtain the real IP address