Jump to content

http_build_query GET URL


seblondres

Recommended Posts

Hi,

 

I'm trying to build a url in the php file below from a url in the browser.

 

URL in the browser: http:/test1.com/directory.php?city=london

 

then I like to get the city and add it at the end of the url in the php file below so it looks like that: http://www.test2.com/directory/london

 

so far I go this but I can only access http://www.test2.com/directory/

<?php$city = $_GET['city'];$fields = array('city' => $city);$url = "http://www.test2.com/directory/". http_build_query($fields, '');?>

Thanks for your help,

 

Link to comment
Share on other sites

Thanks for your answers:

 

The variable $url would be used to scrape this page for example: http://www.test2.com/directory/london-greenwich

 

Here is how it should works:

1. I'm on the index page and I have a link http:/test1.com/directory.php?city=london-greenwich

2. When I click on the link above I'm redirected to directory.php which contain the php file above with the variable $city = $_GET['city'];

3. With this variable $city = $_GET['city']; I should be able to get "london-greenwich"

4. Then I want to add that piece of url "london-greenwich" to $url = "http://www.test2.com/directory/"

5. So I can build the following url $url = "http://www.test2.com/directory/london-greenwich"

 

Thanks,

Edited by seb_london
Link to comment
Share on other sites

http_build_query() does not do what you want.

 

All you need to do is append the value to the URL:

$url = "http://www.test2.com/directory/". $_GET['city'];

I asked what you're planning to do with the variable $url, because from this point on I have no idea what you want.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...