必须创建一个捕获第一个preg_replace栏url的规则


must create a rule that captures the first preg_replace bar url

必须创建一个规则来捕获第一个preg_replace栏url:

http://localhost/item/other

必须取规则just 'item'不管后面是什么

您应该使用php parse_url()函数

一个例子是:

$parts = parse_url("http://localhost/item/other");
$path_parts= explode('/', $parts[path]);
$item = $path_parts[1];
echo $item;

看起来你没有一个具体的问题。我假设你要写一些路由脚本。

    $request_uri = explode('/', $_SERVER['REQUEST_URI']);
    $delimiter = array_shift($request_uri);
    $controller = array_shift($request_uri);
    $action = array_shift($request_uri);
    if(preg_match('/item/i', $controller))
    {
        // do something right
    }
    else 
    {
        // do something wrong
    }