开发者

must create a rule that captures the first preg_replace bar url [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.

Wa开发者_运维技巧nt to improve this question? Add details and clarify the problem by editing this post.

Closed 8 years ago.

Improve this question

must create a rule that captures the first preg_replace bar url:

http://localhost/item/other

must take the rule just 'item' regardless of what comes after


You should use the php parse_url() function

An example would be:

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


It does not look like you have a specific question. I am assuming you are about write some routes script.

    $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
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜