How to remove the last three characters in php

青灯夜游
Release: 2023-03-08 16:36:02
Original
2365 people have browsed it

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}";
?>
Copy after login

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)
Copy after login

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!

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