Php 如何将URL分成多个部分

Php 如何将URL分成多个部分,php,Php,我有下面的URL并存储在一个变量中,该变量是$currentURL $currentURL = http://localhost/example/villa-search/page/2/?features=Beachfront%2CCook%20Services%2CGarden%2CPrivate%20Pool%2CSea%20View 现在,我想将URL分解到节中,并存储在两个不同的变量中 第一部分是: http://localhost/example/villa-search /pag

我有下面的URL并存储在一个变量中,该变量是
$currentURL

$currentURL = http://localhost/example/villa-search/page/2/?features=Beachfront%2CCook%20Services%2CGarden%2CPrivate%20Pool%2CSea%20View
现在,我想将URL分解到节中,并存储在两个不同的变量中

第一部分是:

http://localhost/example/villa-search
/page/2/?features=Beachfront%2CCook%20Services%2CGarden%2CPrivate%20Pool%2CSea%20View
第二部分是:

http://localhost/example/villa-search
/page/2/?features=Beachfront%2CCook%20Services%2CGarden%2CPrivate%20Pool%2CSea%20View
如何做到这一点?

您可以使用PHP并从中获取组件,然后从中重新构建所需的格式。
然后使用从parse_url()获得的查询部分。

您可以使用正则表达式来执行此操作。您好,谢谢您的建议。