Home  >  Article  >  Backend Development  >  How to remove string from string in php

How to remove string from string in php

藏色散人
藏色散人Original
2020-11-03 14:07:002414browse

php method to remove strings in strings: first create a PHP sample file; then define a set of strings; finally remove the specified string through the "str_replace" function.

How to remove string from string in php

Recommendation: "PHP Video Tutorial"

php Remove a string from the string

The code is as follows:

$str = 'abc123abc';
echo str_replace('123', '', $str);

str_replace() function replaces some characters in a string (case sensitive).

This function must follow the following rules:

If the searched string is an array, then it will return an array.

If the searched string is an array, then it will find and replace each element in the array.

If an array needs to be searched and replaced at the same time, and the elements to be replaced are less than the number of found elements, the excess elements will be replaced with empty strings.

If you search an array and replace only one string, the replacement string will work on all found values.

Note: This function is case-sensitive. Please use the str_ireplace() function to perform a case-insensitive search.

Note: This function is binary safe.

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