How to delete specified characters in a string in php?

青灯夜游
Release: 2023-03-07 07:18:01
Original
7011 people have browsed it

The str_replace() function can be used in php to delete the specified characters in the string; the str_replace() function can replace the specified characters in the string. When the replaced value is a null character, the specified characters can be deleted. Character, the syntax is "str_replace('specified character','', string)".

How to delete specified characters in a string in php?

Recommendation: "PHP Video Tutorial"

str_replace() function replaces some characters in the string (differentiate case) and returns a string or array with the replacement value.

Syntax:

str_replace(find,replace,string,count)
Copy after login

Parameters:

  • find Required. Specifies the value to look for.

  • replace Required. Specifies the value to replace the value in find.

  • string Required. Specifies the string to be searched for.

  • count Optional. A variable counting the number of substitutions.

str_replace() function must follow the following rules:

  • If the searched string is an array, then it will return an array.

  • If the searched string is an array, then it will find and replace each element in the array.

  • If an array needs to be searched and replaced at the same time, and the elements to be replaced are less than the number of found elements, the excess elements will be replaced with empty strings .

  • If you search an array and replace only one string, the replacement string will work for all found values.

php deletes the specified characters in the string

The str_replace() function can replace the specified characters in the string. When the replacement value is When the empty character ('') is entered, the specified character can be deleted

Example: Use the str_replace() function to replace the h character of the string with empty, thereby deleting the specified character in the string.

How to delete specified characters in a string in php?

Output result:

How to delete specified characters in a string in php?

For more programming-related knowledge, please visit:Introduction to Programming ! !

The above is the detailed content of How to delete specified characters in a string 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!