jjzjj

whatINeed

全部标签

php - 请求 uri php : get first level

如果我有一个url,例如www.example.com/test/example/product.html我怎么才能得到测试部分(所以是顶级)我知道您会使用$_SERVER['REQUEST_URI']并且可能使用substr或trim但是我不确定该怎么做,谢谢! 最佳答案 用explode将字符串拆分成一个数组,然后取出你需要的部分。$whatINeed=explode('/',$_SERVER['REQUEST_URI']);$whatINeed=$whatINeed[1];如果您使用PHP5.4,您可以执行$whatINeed