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

How to delete specified characters in a string in php

Guanhui
Guanhui Original
2020-05-11 13:53:36 23251browse

How to delete specified characters in a string in php

How to delete specified characters in a string in php

1. You can replace the specified characters with empty characters by using the "str_replace()" function , to achieve the effect of deleting the specified characters.

$str="abcdefg"; $str=str_replace('a','',$str); echo $str;

2. Use the "substr_replace()" function and the "strpos()" function together to replace the specified characters with empty characters.

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

Recommended tutorial: "PHP Tutorial"

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