Reputation: 10590
this is my code
$method = $_SERVER['PATH_INFO'];
and this is my path:
http://localhost:8082/XXXX/controllers/User.php/newUser?name=hello
the result of the method is /newUser
I would like to have just newUser
. IE without the /
could you help me please
Upvotes: 5
Views: 483
Reputation: 501
Maybe your question already exist:
URL: PHP How to remove last part of a path
One solution:
preg_replace("/\/\w+$/i","",__DIR__);
# Note you may also need to add .DIRECTORY_SEPARATOR at the end.
Another solution:
dirname($path)
Documentation: http://ca3.php.net/dirname
Upvotes: 2
Reputation: 18578
use ltrim
on the variable you want ? Seems the easiest way to me
$var = ltrim($var,"/");
Upvotes: 6