PHP:在第三个字符上爆炸


PHP: Explode on 3rd character

我遇到了一个问题,我正在使用dirname($_SERVER['PHP_SELF']);来获取当前页面的url,我最终得到了这个/clients/sherloc_media/install,我试图使用explode()来获取这个/clients/sherloc_media,我需要这个作为一个变量,然后我需要sherloc_media作为另一个变量。在过去的几个小时里,我一直在尝试这样做,因为我将使用/clients/sherloc_media作为$root变量,

不知怎么的,我最终得到了这样的链接http://localhost/clients/sherloc_media/operate/opertate/index.php

当它被假定为http://localhost/clients/sherloc_media/opertate/index.php

任何帮助都将是伟大的,谢谢,我没有任何代码,我已经删除并重新开始了,你知道的裂缝,欢呼

多种方法之一:

$firstPart = substr(rtrim($path, '/'), 0, strrpos($path, '/'));

或者,如果你喜欢爆炸:

$parts = explode('/', trim($path, '/'));
$firstPart = $parts[0] . '/' . $parts[1];