PHP 从路径中删除最后一个“/”


php remove the last "/" from the path

这是我的代码

 $method = $_SERVER['PATH_INFO'];

这是我的道路:

http://localhost:8082/XXXX/controllers/User.php/newUser?name=hello

该方法的结果是/newUser

我只想newUser.不带/的IE

你能帮我吗

你想要的变量上使用ltrim?对我来说似乎是最简单的方法

$var = ltrim($var,"/");
$method = ltrim($_SERVER['PATH_INFO'], '/');
$withoutSlash = substr($_SERVER['PATH_INFO'], 1);

也许你的问题已经存在:

网址: PHP 如何删除路径的最后一部分

一个解决方案:

 preg_replace("/'/'w+$/i","",__DIR__);
 # Note you may also need to add .DIRECTORY_SEPARATOR at the end.

另一种解决方案:

dirname($path)
Documentation: http://ca3.php.net/dirname