如何将URL分成几个部分

时间:2014-03-06 04:46:18

标签: php

我有一个以下URL并存储在一个$currentURL变量中。

$currentURL = http://localhost/example/villa-search/page/2/?features=Beachfront%2CCook%20Services%2CGarden%2CPrivate%20Pool%2CSea%20View

现在我想将URL分解为section并存储在两个不同的变量中

第一部分是:

http://localhost/example/villa-search

第二部分是:

/page/2/?features=Beachfront%2CCook%20Services%2CGarden%2CPrivate%20Pool%2CSea%20View

如何实现这一目标?

1 个答案:

答案 0 :(得分:2)

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

相关问题