在PHP有任何方式加载部分网址

时间:2014-01-29 06:47:02

标签: php

在php中有任何方法可以加载部分url

例如:www.xyz.com/courses/six-sigma-green-belt-training-bangalore是当前网址,我想加载页面直到此网址www.xyz.com/courses/six-sigma-green-belt-training

请帮忙。

1 个答案:

答案 0 :(得分:1)

您可以使用这个简单的网址导航类

class coursesNav {
    private $baseurl = 'www.xyz.com/courses/';
    private $pieces = array();
    public function __construct($url) {
        $this->pieces = explode('-', substr($url, strlen($this->baseurl)));
    }

    public function getLevel($pos) {
        return $this->baseurl.implode('-', array_slice($this->pieces, 0, $pos));
    }
}

$nav = new coursesNav('www.xyz.com/courses/six-sigma-green-belt-training-bangalore');
echo $nav->getLevel(5);