How to remove the square brackets at both ends of a string in php

青灯夜游
Release: 2023-03-15 14:50:02
Original
2861 people have browsed it

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,"]"),"[")".

How to remove the square brackets at both ends of a string in php

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,"]"),"[");
?>
Copy after login

How to remove the square brackets at both ends of a string in php

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!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!