Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从URL获取字符串_Php_String_Url - Fatal编程技术网

Php 从URL获取字符串

Php 从URL获取字符串,php,string,url,Php,String,Url,我有一个小问题,我需要从URL中提取一个字符串,如下所示: http://www.myserver.com/category/firstcat/second-cat/ 我所有的URL都有这种结构,我需要捕获“firstcat”字符串 谢谢你的帮助 非常感谢 您不是在使用mod_rewrite吗?在htaccess中放置规则: RewriteRule ([a-zA-Z]+)/([a-zA-Z]+)/([a-zA-Z]+)/ ?cat=$1&subcat=$2&name=$3 您

我有一个小问题,我需要从URL中提取一个字符串,如下所示:

http://www.myserver.com/category/firstcat/second-cat/
我所有的URL都有这种结构,我需要捕获“firstcat”字符串

谢谢你的帮助


非常感谢

您不是在使用mod_rewrite吗?在htaccess中放置规则:

RewriteRule ([a-zA-Z]+)/([a-zA-Z]+)/([a-zA-Z]+)/ ?cat=$1&subcat=$2&name=$3

您将在$\u GET数组中准备好它。

您不是在使用mod\u rewrite吗?在htaccess中放置规则:

RewriteRule ([a-zA-Z]+)/([a-zA-Z]+)/([a-zA-Z]+)/ ?cat=$1&subcat=$2&name=$3

您将在$\u GET数组中准备好它。

如果您试图在用户所在的当前url上执行此操作,则需要
$\u服务器['REQUEST\u URI']
。这将显示当前打开的uri,在本例中为
/category/firstcat/second cat/

然后使用您喜欢的任何东西来解析字符串并获得所需的元素,例如:

$elms = explode('/', $uri) ;
$firstcat = $elms[2] ;

如果您试图在用户所在的当前url上执行此操作,则需要
$\u服务器['REQUEST\u URI']
。这将显示当前打开的uri,在本例中为
/category/firstcat/second cat/

然后使用您喜欢的任何东西来解析字符串并获得所需的元素,例如:

$elms = explode('/', $uri) ;
$firstcat = $elms[2] ;