String related functions in php

墨辰丷
Release: 2023-03-25 19:24:02
Original
1645 people have browsed it

This article mainly introduces string related functions in php. Interested friends can refer to it. I hope it will be helpful to everyone.

1. Function to find character position:
strpos(

The first occurrence in str The position of


stripos($str,search,[int]): Returns the position of the first occurrence of a string in another string. This function is useful for Case insensitive

strrpos(

The last occurrence of str in position, starting from int


strripos($str,search,[int]): Same as above, but is not case sensitive

2. Extract substring function ( Double bytes)
substr($str,int start[,int length]): Intercept the length string starting from the start position. If length is empty, intercept it to the end

strstr(

str2): intercept from

str2 from the beginning to the end, if not Then return false


stristr(

##str2): The function is the same as strstr, but it is not case sensitive


strrchr(

##str2): intercept backwards from the last searched character; Can be used to get the file name


3. Replace the string

str_replace(search,replace,


Search search in str

Use replace to replace


##str_ireplace(search,replace,$str): Same as above, this function is not case sensitive

strtr($str,search,replace): replace in this function cannot be "";

substr_replace(

rep ,

str original string,

start starting position, $length replacement The length of

int strcmp(


str2):

str2 respectively Is positive 1,0,-1 (string comparison)

strcasecmp() Same as above (not case sensitive)

strnatcmp("4", "14") Compare strings in natural order strnatcasecmp() Same as above, (case sensitive)

6. PHP string function split into arrays

str_split(


str is split according to the length of len and returns the array

split(search,

str is divided according to the search character and the returned array int is divided several times, and the subsequent ones will not be divided expload(search,$str[,int])


7. Remove spaces:

ltrim(), rtrim(), trim()Related recommendations:

PHP characters String definition methods and their differences


PHP string encryption enhanced version

How to convert PHP string into an array

The above is the detailed content of String related functions in php. 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