Home Backend Development PHP Tutorial Summary of commonly used functions in php

Summary of commonly used functions in php

Oct 10, 2017 am 09:57 AM
php Summarize tidy

PHP string functions are an integral part of PHP core. No installation is required to use these functions.

Function Description
addcslashes() Returns adding a backslash before the specified character bar string.
addslashes() Returns a string with backslashes added before predefined characters.
bin2hex() Convert a string of ASCII characters to a hexadecimal value.
chop() Remove blank characters or other characters on the right side of the string.
chr() Returns the character from the specified ASCII value.
chunk_split() Split the string into a series of smaller parts.
convert_cyr_string() Convert a string from one Cyrillic character set to another.
convert_uudecode() Decode the uuencode encoded string.
convert_uuencode() Encode a string using the uuencode algorithm.
count_chars() Returns information about the characters used in a string.
crc32() Calculate the 32-bit CRC of a string.
crypt() One-way string encryption (hashing).
echo() Output one or more strings.
explode() Break up the string into an array.
fprintf() Write the formatted string to the specified output stream.
get_html_translation_table() Returns the translation table used by htmlspecialchars() and htmlentities().
hebrev() Convert Hebrew text to visible text.
hebrevc() Convert Hebrew text to visible text and convert new lines (\n) to
.
hex2bin() Convert a string of hexadecimal values ​​to ASCII characters.
html_entity_decode() Convert HTML entities to characters.
htmlentities() Convert characters to HTML entities.
htmlspecialchars_decode() Convert some predefined HTML entities into characters.
htmlspecialchars() Convert some predefined characters into HTML entities.
implode() Returns a string composed of array elements.
join() An alias for implode().
lcfirst() Convert the first character of the string to lowercase.
levenshtein() Returns the Levenshtein distance between two strings.
localeconv() Returns local number and currency format information.
ltrim() Remove whitespace characters or other characters on the left side of the string.
md5() Computes the MD5 hash of a string.
md5_file() Calculate the MD5 hash of the file.
metaphone() Calculate the metaphone key of a string.
money_format() Returns a string formatted as a currency string.
nl_langinfo() Returns specific local information.
nl2br() Insert an HTML newline character before each new line in the string.
number_format() Format a number in thousands groups.
ord() Returns the ASCII value of the first character in the string.
parse_str() Parse the query string into variables.
print() Output one or more strings.
printf() Output formatted string.
quoted_printable_decode() Convert quoted-printable string to 8-bit string.
quoted_printable_encode() Convert 8-bit string to quoted-printable string.
quotemeta() Quote metacharacters.
rtrim() Remove whitespace characters or other characters on the right side of the string.
setlocale() Set regional information (regional information).
sha1() Computes the SHA-1 hash of a string.
sha1_file() Compute the SHA-1 hash of a file.
similar_text() Calculate the similarity of two strings.
soundex() Calculate the soundex key of a string.
sprintf() Write the formatted string into the variable.
sscanf() Parses input from a string according to the specified format.
str_getcsv() Parse the CSV string into an array.
str_ireplace() Replace some characters in a string (not case sensitive).
str_pad() Padding the string to the new length.
str_repeat() Repeat the string the specified number of times.
str_replace() Replace some characters in the string (case sensitive).
str_rot13() Perform ROT13 encoding on a string.
str_shuffle() Randomly shuffles all characters in the string.
str_split() Split the string into an array.
str_word_count() Count the number of words in a string.
strcasecmp() Compares two strings (not case sensitive).
strchr() Find the first occurrence of a string in another string. (Alias ​​for strstr().)
strcmp() Compares two strings (case sensitive).
strcoll() Compares two strings (according to local settings).
strcspn() Returns the number of characters to search in a string before finding any part of some specified characters.
strip_tags() Strip HTML and PHP tags from strings.
stripcslashes() Remove backslashes added by the addcslashes() function.
stripslashes() Remove backslashes added by addslashes() function.
stripos() Returns the position of the first occurrence of a string in another string (not case sensitive).
stristr() Find the first occurrence of a string in another string (case insensitive).
strlen() Returns the length of the string.
strnatcasecmp() Uses a "natural ordering" algorithm to compare two strings (not case sensitive).
strnatcmp() Uses a "natural ordering" algorithm to compare two strings (case sensitive).
strncasecmp() String comparison of the first n characters (not case sensitive).
strncmp() String comparison of the first n characters (case sensitive).
strpbrk() Find any character in a set of characters in a string.
strpos() Returns the position of the first occurrence of a string in another string (case sensitive).
strrchr() Find the last occurrence of a string in another string.
strrev() Reverse a string.
strripos() Find the last occurrence of a string in another string (not case sensitive).
strrpos() Find the last occurrence of a string in another string (case sensitive).
strspn() Returns the number of specific characters contained in a string.
strstr() Find the first occurrence of a string in another string (case sensitive).
strtok() Split the string into smaller strings.
strtolower() Convert the string to lowercase letters.
strtoupper() Convert the string to uppercase letters.
strtr() Convert specific characters in the string.
substr() Returns a part of the string.
substr_compare() Compares two strings starting at the specified starting position (binary safe and selective case sensitive).
substr_count() Count the number of times a substring appears in a string.
substr_replace() Replace part of a string with another string.
trim() Remove whitespace characters and other characters on both sides of the string.
ucfirst() Convert the first character in the string to uppercase.
ucwords() Convert the first character of each word in the string to uppercase.
vfprintf() Write the formatted string to the specified output stream.
vprintf() Output formatted string.
vsprintf() Write the formatted string into the variable.
wordwrap() Break the string into a specified number of words

Example during form validation Use function:

function test_input($data) {
  $data = trim($data);            //移除字符串两侧的空白字符和其他字符。
  $data = stripslashes($data);      //删除由 addslashes() 函数添加的反斜杠。
  $data = htmlspecialchars($data);   //把一些预定义的字符转换为 HTML 实体。
  return $data;
}
Copy after login

The above is the detailed content of Summary of commonly used functions in php. For more information, please follow other related articles on the PHP Chinese website!

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

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

To work on file upload we are going to use the form helper. Here, is an example for file upload.

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

In this chapter, we are going to learn the following topics related to routing ?

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

Validator can be created by adding the following two lines in the controller.

See all articles