Home  >  Article  >  Backend Development  >  How to remove the last three characters in php

How to remove the last three characters in php

青灯夜游
青灯夜游Original
2021-03-11 17:42:412402browse

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) ".

How to remove the last three characters in php

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(&#39;content-type:text/html;charset=utf-8&#39;); 
$str = &#39;programming&#39;;
echo "原字符串:{$str}<br /><br />";
//定义一个字符串
$res = substr($str, -3);
//处理字符串

echo "返回要去除的最后3个字符:{$res}<br />";
$res = substr($str, 0, -3);
//处理字符串
echo "<br />返回除去最后3个字符后的字符串:{$res}";
?>

Output:

How to remove the last three characters in php

[Recommended learning: "PHP Video Tutorial"]

Related function description:

substr() function returns a part of the string.

Syntax

substr(string,start,length)

How to remove the last three characters in php

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!

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