在php中有任何方法可以加载部分url
例如:www.xyz.com/courses/six-sigma-green-belt-training-bangalore
是当前网址,我想加载页面直到此网址www.xyz.com/courses/six-sigma-green-belt-training
请帮忙。
答案 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);