Home Backend Development PHP Tutorial Discuss the summary analysis of various PHP string functions_PHP tutorial

Discuss the summary analysis of various PHP string functions_PHP tutorial

Jul 21, 2016 pm 03:09 PM
php Location function analyze character string Summarize Discuss extract replace Find Compare of length

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[,'

']): Remove HTML and PHP tags

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/327300.htmlTechArticlePHP string functions include find character position functions; extract sub-character functions; replace strings; character length; compare characters Function; split into array characters; remove spaces, etc. PHP language...
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)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 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)

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.

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

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.

CakePHP Logging CakePHP Logging Sep 10, 2024 pm 05:26 PM

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

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 Services CakePHP Services Sep 10, 2024 pm 05:26 PM

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

See all articles