Home >Backend Development >PHP Problem >How to remove first and last characters in php

How to remove first and last characters in php

王林
王林Original
2020-08-28 14:55:302440browse

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)

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);
?>

Running result:

Without trim: Hello World!
With trim: Hello World!

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!

Statement:
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