Home > Article > Backend Development > How to remove the last three characters in php
In PHP, you can use the substr() function to remove the last three characters of a string. This function can return a part of the string; the specific syntax format is "substr(specified string, 0,-3) ".
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
php removes the last three characters of the string Characters
<?php header('content-type:text/html;charset=utf-8'); $str = 'programming'; echo "原字符串:{$str}<br /><br />"; //定义一个字符串 $res = substr($str, -3); //处理字符串 echo "返回要去除的最后3个字符:{$res}<br />"; $res = substr($str, 0, -3); //处理字符串 echo "<br />返回除去最后3个字符后的字符串:{$res}"; ?>
Output:
[Recommended learning: "PHP Video Tutorial"]
Related function description:
substr() function returns a part of the string.
Syntax
substr(string,start,length)
Note: If the start parameter is negative and length is less than or equal to start, length is 0.
For more programming related knowledge, please visit: Programming Video! !
The above is the detailed content of How to remove the last three characters in php. For more information, please follow other related articles on the PHP Chinese website!