Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php remove the last "/" from the path

Tags:

php

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

like image 502
Marco Dinatsoli Avatar asked Dec 11 '14 14:12

Marco Dinatsoli


2 Answers

use ltrim on the variable you want ? Seems the easiest way to me

$var = ltrim($var,"/");
like image 191
exussum Avatar answered Sep 23 '22 21:09

exussum


$method = ltrim($_SERVER['PATH_INFO'], '/');
like image 30
Legionar Avatar answered Sep 26 '22 21:09

Legionar