gpt4 book ai didi

php - 如何获取 PHP 字符串的最后 7 个字符?

转载 作者:IT老高 更新时间:2023-10-28 11:38:51 25 4
gpt4 key购买 nike

我将如何获取下面字符串的最后 7 个字符?

例如:

$dynamicstring = "2490slkj409slk5409els";
$newstring = some_function($dynamicstring);
echo "The new string is: " . $newstring;

将显示的内容:

The new string is: 5409els

最佳答案

使用 substr()第二个参数为负数。

$newstring = substr($dynamicstring, -7);

来自php docs :

string substr ( string $string , int $start [, int $length ] )

If start is negative, the returned string will start at the start'th character from the end of string.

关于php - 如何获取 PHP 字符串的最后 7 个字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10542310/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com