How to delete specified characters in a string in php

Guanhui
Release: 2023-03-01 07:26:01
Original
23239 people have browsed it

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;
Copy after login

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);
Copy after login

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!

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
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!