Home > Backend Development > PHP Tutorial > Summary of commonly used functions and global variables in PHP (recommended)

Summary of commonly used functions and global variables in PHP (recommended)

不言
Release: 2023-04-03 14:16:01
Original
1949 people have browsed it

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.

1. PHP built-in function

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');
Copy after login

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(), &#39;5.6.0&#39;, &#39;<&#39;)) {
	exit(&#39;PHP5.6+ Required&#39;);
}
Copy after login

2. Super global variables

$_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

3. Common PHP encapsulated functions:

1. Determination Is it an HTTPS request?

// 检查是否是HTTPS请求
if ((isset($_SERVER[&#39;HTTPS&#39;]) && (($_SERVER[&#39;HTTPS&#39;] == &#39;on&#39;) || ($_SERVER[&#39;HTTPS&#39;] == &#39;1&#39;))) || (isset($_SERVER[&#39;HTTPS&#39;]) && (isset($_SERVER[&#39;SERVER_PORT&#39;]) && $_SERVER[&#39;SERVER_PORT&#39;] == 443))) {
    $_SERVER[&#39;HTTPS&#39;] = true;
} elseif (!empty($_SERVER[&#39;HTTP_X_FORWARDED_PROTO&#39;]) && $_SERVER[&#39;HTTP_X_FORWARDED_PROTO&#39;] == &#39;https&#39; || !empty($_SERVER[&#39;HTTP_X_FORWARDED_SSL&#39;]) && $_SERVER[&#39;HTTP_X_FORWARDED_SSL&#39;] == &#39;on&#39;) {
    $_SERVER[&#39;HTTPS&#39;] = true;
} else {
    $_SERVER[&#39;HTTPS&#39;] = false;
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template