PHP substr

php中substr函数的用法是什么

小亿
112
2023-08-17 18:00:56
栏目: 编程语言
PHP开发者专用服务器,限时0元免费领! 查看>>

substr函数是用于提取字符串的一部分。它的用法如下:

substr(string $string, int $start, int|null $length = null): string|false

参数说明:

返回值:

示例:

$str = "Hello World";
echo substr($str, 0, 5); // 输出 "Hello"
$str = "Hello World";
echo substr($str, -5); // 输出 "World"

上述示例中,第一个substr函数调用提取了字符串$str的前5个字符,第二个substr函数调用提取了字符串$str的最后5个字符。

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

相关推荐:PHP substr()函数的用法是什么

0
看了该问题的人还看了