search

PHP5 common functions

Dec 01, 2016 am 11:51 AM
xml

PHP has been updated to many versions, and the one that is used more recently is PHP5. Below we have summarized the common functions of PHP5 for you so that you can check them when actually writing code in the future.

pathinfo returns file path information, including the following array units: dirname, basename and extension.

func_num_args(), func_get_arg(), func_get_args()
glob— Find file paths matching the pattern
gzcompress() and gzuncompress() functions:
json_encode() and json_decode()
serialize() and unserialize() in My personal experience mainly deals with array transfer and array storage operations.

is_dir
mb_detect_encoding Automatically obtains the string encoding function
usleep() function delays code execution for several microseconds.
unpack() function unpacks data from a binary string. The
uniqid () function generates a unique ID based on the current time in microseconds.
time_sleep_until() function delays code execution until the specified time.
The time_nanosleep() function, a commonly used function in PHP5, delays code execution for a number of seconds and nanoseconds.
sleep() function delays code execution for a few seconds.
show_source() function performs syntax highlighting on files. The
strip_whitespace() function returns the source code file with PHP comments and whitespace characters removed. The
pack() function loads data into a binary string.
ignore_user_abort() function sets whether disconnecting from the client will terminate the execution of the script.
highlight_string() function performs syntax highlighting on strings.
highlight_file() function performs syntax highlighting on files.
The get_browser() function, a commonly used function in PHP5, returns the performance of the user's browser. The
eval() function evaluates strings according to PHP code.
defined() function checks whether a constant exists.
define() function defines a constant.
constant() function returns the value of a constant.
The connection_status() function, a commonly used function in PHP5, returns the current connection status.
connection_aborted() function checks whether the client is disconnected.
utf8_encode() function encodes ISO-8859-1 string to UTF-8.
utf8_decode() function decodes UTF-8 string to ISO-8859-1.
The wordwrap () function wraps the string according to the specified length.
nl2br
fgetcsv

vsprintf() function writes the formatted string into a variable.
vprintf() function outputs a formatted string.
vfprintf() function writes the formatted string to the specified output stream.
The ucwords () function, a commonly used function in PHP5, converts the first character of each word in the string to uppercase.
ucfirst() function converts the first character in a string to uppercase.
trim() function removes whitespace characters and other predefined characters from both ends of a string.
substr_replace() function replaces part of a string with another string.
substr_count() function counts the number of times a substring appears in a string.
substr_compare() function compares two strings from a specified starting length.
substr() function returns a part of a string.
strtr() function converts specific characters in a string.
The strtok() function, a commonly used function in PHP5, splits a string into smaller strings.
strstr() function searches for the first occurrence of a string within another string.
strspn() function returns the number of specific characters contained in a string.
strrpos() function finds the last occurrence of a string within another string.
strripos() function finds the last occurrence of a string within another string.
strrev() function reverses a string.
strrchr() function finds the last occurrence of a string in another string and returns all characters from that position to the end of the string.
strpos() function returns the position of the first occurrence of a string in another string.
The strpbrk() function, a commonly used function in PHP5, searches for any one of the specified characters in a string.
strncmp() function compares two strings.
strncasecmp() function compares two strings.
strnatcmp() function uses a "natural" algorithm to compare two strings.
strnatcasecmp() function uses a "natural" algorithm to compare two strings.
strlen() function returns the length of the string.
stristr() function finds the first occurrence of a string within another string.
stripos() function returns the position of the first occurrence of a string in another string. ​
The stripslashes () function removes the backslashes added by the addslashes() function.
stripcslashes() function removes backslashes added by addcslashes() function.
strip_tags() function strips HTML, XML and PHP tags.
strcspn() function returns the number of characters searched in a string before any specified character is found.
The strcoll() function, a commonly used function in PHP5, compares two strings.
strcmp () function compares two strings.
strchr() function searches for the first occurrence of a string within another string.
strcasecmp() function compares two strings.
str_word_count() function counts the number of words in a string.
str_split() function splits a string into an array.
str_shuffle () function randomly shuffles all characters in a string.
str_rot13() function performs ROT13 encoding on a string.
str_replace() function uses a string to replace other characters in a string.
str_repeat() function repeats a string a specified number of times.
str_pad() function pads the string to the specified length.
str_ireplace() function uses a string to replace other characters in a string.
PHP5 commonly used function sscanf() function parses input from a string according to the specified format.
sprintf () function writes the formatted string into a variable.
soundex() function calculates the soundex key of a string.
similar_text() function counts the number of matching characters in two strings. The
sha1_file() function calculates the SHA-1 hash of a file. The
sha1() function computes the SHA-1 hash of a string.
setlocale() function sets regional information (regional information).
PHP5 commonly used functions rtrim() P rtrim() function

basename — Returns the file name part of the path

dirname — Returns the directory part of the path

array_filter — Filters the units in the array with a callback function
array_flip — Exchange Keys and values ​​in the array

array_count_values ​​determines the number of times a character appears in the string

array_uintersect — Calculate the intersection of arrays, use callback functions to compare data
array_unique — Remove duplicate values ​​in the array array_flip(array_flip())

arsort — Sort the array in reverse order and maintain the index relationship

array_sum — Calculate the sum of all values ​​in the array

array_search — Search the array for a given value, returning the corresponding key name if successful

in_array — Check the array Whether there is a certain value

array_push — push one or more units to the end of the array (push)

array_unshift() function inserts one or more elements at the beginning of the array

array_values ​​returns all the values ​​in the input array and Create a numerical index for it. ////Use the array_values ​​function to reindex

count_chars Returns the information of the characters used in the string

array_keys Returns all the key names in the array

array_slice Takes a segment from the array

key() Returns the current unit in the array Key name .

get_class_methods — Returns an array consisting of the method names of the class
get_class_vars — Returns an array consisting of the default attributes of the class
get_class — Returns the class name of the object
get_declared_classes — Returns an array consisting of the names of defined classes
get_declared_interfaces — Returns An array containing all declared interfaces
get_object_vars — Returns an associative array composed of object attributes
get_parent_class — Returns the parent class name of the object or class
interface_exists — Checks whether the interface has been defined
is_a — If the object belongs to this class or class If it is the parent class of this object, return TRUE
is_subclass_of — If this object is a subclass of this class, return TRUE
method_exists — Check whether the method of the class exists
property_exists — Check whether the object or class has this property

parse_str (url, arr) is to convert a url? The following parameters into an array
parse_url (string url) is to parse a complete url into an array
http_build_query is to convert an array into a url? The following parameter string will be automatically Perform urlencode processing
call_user_func_array

ctype_alnum -- Check whether it only contains [A-Za-z0-9]
ctype_alpha -- Check whether it only contains [A-Za-z]
ctype_cntrl -- Check whether it only contains classes It is a character control character such as " "
ctype_digit -- When checking, it is a string containing only numeric characters (0-9). Negative numbers and decimals will not be detected.

filter_var($email, FILTER_VALIDATE_EMAIL)
ctype_graph --Check whether It is a string that only contains characters that can be printed (except spaces)
ctype_lower -- Checks whether all characters are English letters and all are lowercase
ctype_print -- Checks whether it only contains characters that can be printed The string
ctype_punct -- Check whether it only contains printable characters that are not numbers/characters/spaces
ctype_space -- Check whether it only contains characters and spaces such as " "
ctype_upper -- Check whether all The characters are all English letters, and they are all uppercase
ctype_xdigit -- Check whether it is a hexadecimal string, which can only include "0123456789abcdef"


Statement
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
How to make PHP applications fasterHow to make PHP applications fasterMay 12, 2025 am 12:12 AM

TomakePHPapplicationsfaster,followthesesteps:1)UseOpcodeCachinglikeOPcachetostoreprecompiledscriptbytecode.2)MinimizeDatabaseQueriesbyusingquerycachingandefficientindexing.3)LeveragePHP7 Featuresforbettercodeefficiency.4)ImplementCachingStrategiessuc

PHP Performance Optimization Checklist: Improve Speed NowPHP Performance Optimization Checklist: Improve Speed NowMay 12, 2025 am 12:07 AM

ToimprovePHPapplicationspeed,followthesesteps:1)EnableopcodecachingwithAPCutoreducescriptexecutiontime.2)ImplementdatabasequerycachingusingPDOtominimizedatabasehits.3)UseHTTP/2tomultiplexrequestsandreduceconnectionoverhead.4)Limitsessionusagebyclosin

PHP Dependency Injection: Improve Code TestabilityPHP Dependency Injection: Improve Code TestabilityMay 12, 2025 am 12:03 AM

Dependency injection (DI) significantly improves the testability of PHP code by explicitly transitive dependencies. 1) DI decoupling classes and specific implementations make testing and maintenance more flexible. 2) Among the three types, the constructor injects explicit expression dependencies to keep the state consistent. 3) Use DI containers to manage complex dependencies to improve code quality and development efficiency.

PHP Performance Optimization: Database Query OptimizationPHP Performance Optimization: Database Query OptimizationMay 12, 2025 am 12:02 AM

DatabasequeryoptimizationinPHPinvolvesseveralstrategiestoenhanceperformance.1)Selectonlynecessarycolumnstoreducedatatransfer.2)Useindexingtospeedupdataretrieval.3)Implementquerycachingtostoreresultsoffrequentqueries.4)Utilizepreparedstatementsforeffi

Simple Guide: Sending Email with PHP ScriptSimple Guide: Sending Email with PHP ScriptMay 12, 2025 am 12:02 AM

PHPisusedforsendingemailsduetoitsbuilt-inmail()functionandsupportivelibrarieslikePHPMailerandSwiftMailer.1)Usethemail()functionforbasicemails,butithaslimitations.2)EmployPHPMailerforadvancedfeatureslikeHTMLemailsandattachments.3)Improvedeliverability

PHP Performance: Identifying and Fixing BottlenecksPHP Performance: Identifying and Fixing BottlenecksMay 11, 2025 am 12:13 AM

PHP performance bottlenecks can be solved through the following steps: 1) Use Xdebug or Blackfire for performance analysis to find out the problem; 2) Optimize database queries and use caches, such as APCu; 3) Use efficient functions such as array_filter to optimize array operations; 4) Configure OPcache for bytecode cache; 5) Optimize the front-end, such as reducing HTTP requests and optimizing pictures; 6) Continuously monitor and optimize performance. Through these methods, the performance of PHP applications can be significantly improved.

Dependency Injection for PHP: a quick summaryDependency Injection for PHP: a quick summaryMay 11, 2025 am 12:09 AM

DependencyInjection(DI)inPHPisadesignpatternthatmanagesandreducesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itallowspassingdependencieslikedatabaseconnectionstoclassesasparameters,facilitatingeasiertestingandscalability.

Increase PHP Performance: Caching Strategies & TechniquesIncrease PHP Performance: Caching Strategies & TechniquesMay 11, 2025 am 12:08 AM

CachingimprovesPHPperformancebystoringresultsofcomputationsorqueriesforquickretrieval,reducingserverloadandenhancingresponsetimes.Effectivestrategiesinclude:1)Opcodecaching,whichstorescompiledPHPscriptsinmemorytoskipcompilation;2)DatacachingusingMemc

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft