How to remove first and last characters in php

王林
Release: 2023-03-05 11:58:01
Original
2390 people have browsed it

How to remove the first and last characters in php: You can use the built-in function trim() to remove them. The trim() function can remove whitespace characters or other predefined characters on both sides of a string and return the modified string, for example: [trim($string)].

How to remove first and last characters in php

Thetrim() function removes whitespace characters or other predefined characters on both sides of a string and returns the modified string.

(Recommended tutorial: php video tutorial)

Syntax:

trim(string,charlist)
Copy after login

Parameter description:

string Required. Specifies the string to be checked

charlist Optional. Specify which characters to delete from the string

(Related recommendations:php training)

Code example:

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

Running result:

Without trim: Hello World!
With trim: Hello World!
Copy after login

The above is the detailed content of How to remove first and last characters in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
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!