php - How to separate URL into to parts

203

I have bellow URL and storing in one variable which is$currentURL.

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

Now I want to break URL in to section and store in two different variables

First Part is:

http://localhost/example/villa-search

second Part is:

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

How to make this possible?

262

Answer

Solution:

You could use PHP's parse_url() and get components from it and re-construct your desired format from it. And then use explode() the query part obtained from parse_url().

People are also looking for solutions to the problem: Enable SSH2 for PHP 5.4.7 in windows 7 x86 Environment

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.