I have search high and low for an answer to my question and I cannot find it. Basically what I want to do is get the path after a php script. ex. "http://www.example.com/index.php/arg1/arg2/arg3/etc/" and get arg1, arg2, arg3, etc in an array. How can I do this in php and once I do this will "http://www.example.com/arg1/arg2/arg3/etc" still return the same results. If not then how can I achieve this?
3条回答 默认 最新
douying6206 2013-11-21 05:26关注Here is how to get the answer, and a few others you will have in the future. Make a script, e.g. "test.php", and just put this one line in it:
<?php phpinfo();Then browse to it with http://www.example.com/test.php/one/two/three/etc
Look through the
$_SERVERvalues for the one that matches what you are after.I see the answer you want in this case in $_SERVER["PATH_INFO"]: "/one/two/three/etc" Then use
explodeto turn it into an array:print_r( explode('/',$_SERVER['PATH_INFO'] );However sometimes
$_SERVER["REQUEST_URI"]is going to be the one you want, especially if using URL rewriting.UPDATE:
Responding to comment, here is what I'd do:
$args = explode('/',$_SERVER['REQUEST_URI']); if($args[0] == 'index.php')array_shift($args);本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报