Home  >  Article  >  Backend Development  >  What is the method to remove specified characters from a string in php

What is the method to remove specified characters from a string in php

王林
王林Original
2020-11-09 10:14:272427browse

The method for PHP to remove specified characters from a string is: first use the strpos function to find the position where the specified character appears in the string; then use the substr_replace function to replace the specified character.

What is the method to remove specified characters from a string in php

strpos() function finds the first occurrence of a string within another string (case sensitive).

substr_replace() function replaces part of a string with another string.

(Learning video recommendation: java video tutorial)

Example:

$a = "abcababa";

$count=strpos($a,"ab");

$str=substr_replace($a,"",$count,2);

Related recommendations: php training

The above is the detailed content of What is the method to remove specified characters from 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