How to remove the last few digits of a string in php

藏色散人
Release: 2023-03-11 12:18:02
Original
2900 people have browsed it

In PHP, you can use the substr function to remove the last few digits of a string. The implementation code statement is such as "echo substr("Hello world",0,5)".

How to remove the last few digits of a string in php

The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer

How to remove the last few digits of a string in php ?

In PHP, you can use the substr function to remove the last few digits of a string.

The substr() function returns a part of a string.

Note: If the start parameter is a negative number and length is less than or equal to start, length is 0.

Example:

Use start and length parameters with different positive and negative numbers:

<?php
echo substr("Hello world",0,10)."<br>";
echo substr("Hello world",1,8)."<br>";
echo substr("Hello world",0,5)."<br>";
echo substr("Hello world",6,6)."<br>";
echo substr("Hello world",0,-1)."<br>";
echo substr("Hello world",-10,-2)."<br>";
echo substr("Hello world",0,-6)."<br>";
echo substr("Hello world",-2-3)."<br>";
?>
Copy after login

Running results:

Hello worl
ello wor
Hello
world
Hello worl
ello wor
Hello
world
Copy after login

Recommended learning: "PHP video tutorial

The above is the detailed content of How to remove the last few digits of a string in php. For more information, please follow other related articles on the PHP Chinese website!

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