删除最后一个字符之前的所有字符[重复]

问题描述 投票:-5回答:2

这个问题在这里已有答案:

请考虑以下字符串:

Hello World

我的目的是删除最后一个字符(“d”)之前的所有字符,不包括最后一个字符。

在PHP中实现这一目标的最有效方法是什么?

php
2个回答
6
投票

在php中使用substr()

<?php 
$str = "Hello World";
echo substr($str, -1);
?>

1
投票

刚拿到最后一个

 substr("Hello World", -1); // returns "d"
© www.soinside.com 2019 - 2024. All rights reserved.