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)].
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!