How to remove the first and last characters of a string in php

王林
Release: 2023-03-05 21:42:02
Original
4862 people have browsed it

How to remove the first and last characters of a string in php: You can use the trim() function to achieve this. The trim() function can remove blank characters or other predefined characters on both sides of a string and return the modified string, such as [trim($str)].

How to remove the first and last characters of a string in php

#If you want to remove characters on both sides of the string, you can use the PHP built-in function trim().

(Recommended tutorial: php video tutorial)

trim() function removes blank characters or other predefined characters on both sides of the string and returns the modified String.

Grammar format:

trim(string,charlist)
Copy after login

Example:

<?php
$str = " Hello World! ";
echo "Without trim: " . $str;
echo "<br>";
echo "With trim: " . trim($str);
?>
Copy after login

Related recommendations: php training

The above is the detailed content of How to remove the first and last characters 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