gpt4 book ai didi

php - 请求 uri php : get first level

转载 作者:可可西里 更新时间:2023-11-01 13:33:44 26 4
gpt4 key购买 nike

如果我有一个 url,例如 www.example.com/test/example/product.html

我怎么才能得到测试部分(所以是顶级)

我知道您会使用 $_SERVER['REQUEST_URI'] 并且可能使用 substrtrim

但是我不确定该怎么做,谢谢!

最佳答案

explode将字符串拆分成一个数组,然后取出你需要的部分。

$whatINeed = explode('/', $_SERVER['REQUEST_URI']);
$whatINeed = $whatINeed[1];

如果您使用 PHP 5.4,您可以执行 $whatINeed = explode('/', $_SERVER['REQUEST_URI'])[1];

关于php - 请求 uri php : get first level,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10660883/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com