How to delete specified string in php string

王林
Release: 2023-03-06 08:38:01
Original
2771 people have browsed it

php method to delete a specified string in a string: 1. Use the strpos function to find the position of the string; 2. Use the strlen function to calculate the length of the string; 3. Use the substr_replace function to replace the specified string. Can.

How to delete specified string in php string

Related function introduction:

(Recommended tutorial: php video tutorial)

## The #strlen() function returns the length of the string.

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

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

Implementation code:


$ex = 'http://img.path.com';
$email= 'http://img.path.com/uploads/20190723/c700499be56d6a97c32985bda0c7745b.png';
$count=strpos($email,"$ex");
$strlen = strlen($ex);
$str=substr_replace($email,"",$count,$strlen);
echo $str;
Copy after login

Related recommendations:

php training

The above is the detailed content of How to delete specified string in php string. 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