Home  >  Article  >  Backend Development  >  How to delete specified characters in a string in php

How to delete specified characters in a string in php

王林
王林Original
2020-09-03 11:48:385793browse

Str_replace() function can be used in php to delete specified characters in a string. The syntax is "str_replace('specified character','', string)"; str_replace() is used to replace strings. A specific character, if the replacement value is set to a null character (''), the specified character can be deleted.

How to delete specified characters in a string in php

#We can choose the str_replace() function to achieve this function. Let’s introduce this function:

(Related recommendations: php training)

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

Function syntax:

str_replace(find,replace,string,count)

Parameter description:

  • 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.

(Recommended tutorial: php video tutorial)

Code example:

How to delete specified characters in a string in php

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!

Statement:
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