How to remove a certain string in php

王林
Release: 2023-03-04 14:38:02
Original
5088 people have browsed it

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

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

Simple code implementation:

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

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!

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