Home  >  Article  >  Backend Development  >  How to remove a certain string in php

How to remove a certain string in php

王林
王林Original
2020-08-15 14:52:265101browse

php method to remove a certain string: first use the strpos() function to find the first occurrence of the specified string in another string; then use the substr_replace() function to remove the found string That’s it.

How to remove a certain string in php

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

(Recommended tutorial: php graphic tutorial)

Syntax:

strpos(string,find,start)

Parameters:

  • string Required. Specifies the string to be searched for.​

  • #find Required. Specifies the characters to search for.​

  • #start Optional. Specifies the location from which to start the search.

substr_replace() function replaces part of a string with another string and returns the replaced string. If string is an array, the array is returned.

(Video tutorial recommendation: php video tutorial)

Grammar:

substr_replace(string,replacement,start,length)

Simple code implementation:

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

The above is the detailed content of How to remove a certain 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