


Discuss the summary analysis of various PHP string functions_PHP tutorial
PHP string functions include find character position functions; extract sub-character functions; replace strings; character length; compare character functions; split into array characters; remove spaces, etc.
The string functions in PHP language are also relatively easy to understand. Today we have summarized nearly 12 PHP string functions for you. We hope it will be helpful to friends who need them again and increase the PHP knowledge base of readers and friends.
1 Search character position function:
strpos($str,search,[int]): Find the search position in $str A position starts from int;
stripos($str,search,[int]):The function returns the position of the first occurrence of a string in another string. This function is not case sensitivestrrpos($str,search,[int]):Find the last occurrence of search in $str starting from int
strripos($str ,search,[int]):Same as above, this function is not case sensitive
2. Extract substring function (double byte)
substr($str,int start[,int length]):From the strat position in $str Start extracting [length length string].
strstr($str1,$str2):Search $str2 from $str1 (the first position) and intercept it from the beginning to the end of the string; if not, return FALSE.
stristr() The function is the same as strstr, but it is not case-sensitive.
strrchr() Returns from the last searched character; Use: Get the file name in the path
3. PHP string function for replacing strings
str_replace(search,replace,$str):Find search from $str and replace with replace
str_ireplace(search,replace,$str):Same as above, this function is not case sensitive
strtr($str,search,replace):replace cannot be used in this function is "";
substr_replace($Str,$rep,$start[,length]):$str original string, $rep replaced new string, $start starting position, The length of $length replacement, this item is optional
4. Character length
int strlen($str)
5. Comparison character function
int strcmp($str1,$str2):$str1>=<$str2 are positive 1,0,-1 respectively (String comparison)
strcasecmp() Same as above (case-insensitive)
strnatcmp("4","14") Compare strings in natural order
strnatcasecmp() Same as above, (case sensitive)
6. PHP string function split into arrays
str_split($str,len):Split $str according to the length of len and return the array
split(search,$str[,int]):Split $str according to search characters and return the array int. How many times will it be split? The rest will not be split.expload(search,$str[,int ])
7. Remove spaces:
ltrim(), rtrim(), trim()
8. Add space function
chunk_split($str,2):Press 2 characters into the $str character to add a space;
9, chr, ord--return the specified character or ascii
10. Functions related to HTML code ']):
nl2br(): convert n to
.
strip_tags($str[,'
All HTML and PHP codes in $str will be removed. The optional parameters are html and PHP codes. The function of the optional parameters is to retain the code written by the optional parameters.
For example: echo strip_tags($text, '
');
htmlspecialchars($str[,parameter]):The page normally outputs HTML code parameters, yes Conversion method
11. PHP string function for character case conversion
strtolower($str): Convert string to lowercase
strtoupper($str ): Convert string to uppercase
ucfirst($str): Convert the first character of the function to uppercase
ucwords($str): Convert the first letter of each word to uppercase
12. Database-related PHP string functions
addslashes($str): Enable single quotes ('), double quotes ("), and backslashes in str Line() with NUL
string converted to ',",\.
magic_quotes_gpc = On: Automatically escape the contents of get, post, and cookie
get_magic_quotes_gpc(): Detect whether magic_quotes_gpc is turned on
stripslashes( ): Remove backslashes from strings

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



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

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

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

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

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

Logging in CakePHP is a very easy task. You just have to use one function. You can log errors, exceptions, user activities, action taken by users, for any background process like cronjob. Logging data in CakePHP is easy. The log() function is provide

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

This chapter deals with the information about the authentication process available in CakePHP.
