This article introduces to you a summary (recommended) of commonly used functions and global variables in PHP. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
A
array_shift() deletes the first element in the array
array_pop() Delete the last element in the array
array_multisort() Return an ascending array
C
call_user_func_array() Call the callback function, and Call an array as a parameter of the callback function
D
define() define constant
debug_backtrace() trace code call information
E
error_reporting(0) Turn off error reporting
error_reporting(E_ERROR | E_WARNING | E_PARSE) Report runtime errors
error_reporting(E_ALL) Report all errors
ini_set("error_reporting", E_ALL) Equivalent to error_reporting(E_ALL)
error_reporting(E_ALL & ~E_NOTICE) Reports all errors except E_NOTICE
explode() will Split the string into an array
implode() Splice the elements in the array into a string
G
1.getenv() Get the value of the environment variable
$_SERVER['HTTP_HOST'] = getenv('HTTP_HOST');
H
header() Sends the original HTTP header to the client
I
is_file() Determines whether it is a file
ini_get() Gets the value of a configuration option
is_set() Whether it has been defined
is_null() Whether it is empty
P
1. phpversion() Current PHP version
R
require_once() Loading File
S
str_replace() Replace some characters in a string with other characters (case sensitive)
strlen() Get a string Length
substr() Return part of the string
str_repalce() Replace part of the string with another part
strtolower() Convert to lowercase
spl_autoload_register() Automatic loading
spl_autoload_extensions() Returns the automatically loaded file extension
U
unset() Destroy
V
1. version_compare( string $version1
, string $version2
[, string $operator
] ) Compare the first version number of PHP version
version1
. version2 The second version number operator operator <, lt, <=, le, >、 gt、>=、 ge、==、 =、eq , !=, <> and ne
For example:
if (version_compare(phpversion(), '5.6.0', '<')) { exit('PHP5.6+ Required'); }
$_SERVER
$_SERVER['DOCUMENT_ROOT']; The document root where the currently running script is located
$_SERVER['DOCUMENT_FILENAME'] The absolute path of the currently executing script
$_SERVER['PHP_SELF'] The file name of the currently executing script
$_SERVER['HTTP_HOST'] Get the current host
$_SERVER['PATH_TRANSLATED'] The base path where the current script is located, non-document root directory
$_SERVER['REQUEST_URI'] The current request path
$ _SERVER['QUERY_STRING'] Query string
$_SERVER['SERVER_PORT'] Server port
$_SERVER['HTTPS'] HTTPS request
Type operator
instanceof Determines whether a variable is an instance of a class
1. Determination Is it an HTTPS request?
// 检查是否是HTTPS请求 if ((isset($_SERVER['HTTPS']) && (($_SERVER['HTTPS'] == 'on') || ($_SERVER['HTTPS'] == '1'))) || (isset($_SERVER['HTTPS']) && (isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == 443))) { $_SERVER['HTTPS'] = true; } elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') { $_SERVER['HTTPS'] = true; } else { $_SERVER['HTTPS'] = false; }
Recommended related articles:
Code implementation of the construction method and destructor method in php
How to implement counting sorting code in PHP
The above is the detailed content of Summary of commonly used functions and global variables in PHP (recommended). For more information, please follow other related articles on the PHP Chinese website!