Home >Backend Development >PHP Problem >How to remove brackets from string in php
In PHP, you can use the "str_replace()" function to remove the brackets in the string. This function is used to replace some characters in the string and is case-sensitive. The syntax is "str_replace("Bracket" ,"",string);".
The operating environment of this article: Windows 10 system, PHP version 7.1, Dell G3 computer.
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.
The syntax is as follows:
str_replace(find,replace,string,count)
Parameter Description
find Required. Specifies the value to look for.
replace Required. Specifies the value to replace the value in find.
string Required. Specifies the string to be searched for.
count Optional. A variable counting the number of substitutions.
Examples are as follows:
<?php echo str_replace("(","","(这段文字左边有个括号"); ?>
Output results:
PHP Video Tutorial 》
The above is the detailed content of How to remove brackets from string in php. For more information, please follow other related articles on the PHP Chinese website!