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

How to delete specified string in php string

王林
王林 Original
2020-09-29 09:09:53 2698browse

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;

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!

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