Home > Article > Backend Development > How to remove the square brackets at both ends of a string in php
php method to remove brackets at both ends of a string: 1. Use the ltrim() function to remove the brackets at the left end of the string; 2. Use the rtrim() function to remove the brackets at the right end of the string. The syntax is " ltrim(rtrim($str,"]"),"[")".
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
php removes strings The brackets at both ends
In PHP, you can use the ltrim() and rtrim() functions to remove the brackets at both ends of the string
The ltrim() function can remove the brackets on the left end of the string
The rtrim() function can remove the brackets on the right end of the string
Example:
<?php header("Content-type:text/html;charset=utf-8"); $str="[0jjhh45678fg0]"; echo ltrim($str,"[")."<br>"; echo rtrim($str,"]")."<br>"; echo ltrim(rtrim($str,"]"),"["); ?>
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to remove the square brackets at both ends of a string in php. For more information, please follow other related articles on the PHP Chinese website!