seblondres Posted February 2, 2015 Share Posted February 2, 2015 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 More sharing options...
Ingolme Posted February 2, 2015 Share Posted February 2, 2015 Where is the variable $url being used? Link to comment Share on other sites More sharing options...
justsomeguy Posted February 2, 2015 Share Posted February 2, 2015 Using http_build_query would produce a URL like this:http://www.test2.com/directory/city=london Link to comment Share on other sites More sharing options...
seblondres Posted February 3, 2015 Author Share Posted February 3, 2015 (edited) 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 February 3, 2015 by seb_london Link to comment Share on other sites More sharing options...
seblondres Posted February 3, 2015 Author Share Posted February 3, 2015 ok I solved my problem, the below does what I want: <?php$city = $_GET['city'];$url = ('http://www.test2.com/directory/'. $city );?> Thanks, Link to comment Share on other sites More sharing options...
Ingolme Posted February 3, 2015 Share Posted February 3, 2015 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 More sharing options...
seblondres Posted February 3, 2015 Author Share Posted February 3, 2015 ok good to know, I'll put more information next time. thanks a lot! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now