0

I'm trying to generate an URL from all values of two arrays by using http_build_query:

Array 1:

$server = array($_GET["server"]);

Array 2:

$data = array($_GET["z_koord"],
        $_GET['x_koord'],
        $_GET["y_koord"],);

The code for generating URL I currently have written:

$server = array(''=>$_GET["server"]);
$data = array($_GET["z_koord"],
        $_GET['x_koord'],
        $_GET["y_koord"],);
$url = '.tile.openstreetmap.org';
$saite = http_build_query($server). $url ."/". http_build_query($data,'','/').".png";

Here's the URL made of code above:

=c.tile.openstreetmap.org/0=6/1=90/2=110.png

Here's the structure of url I'm trying to make:

c.tile.openstreetmap.org/6/90/110.png

I have reviewed some other posts about this topic like this one and this, but those posts aren't completely useful for solving my problem.

So I hope someone with greater knowledge could show me a solution or at least a hint how to get closer to solution.

2
  • You’re using completely the wrong function to begin with. The purpose of http_build_query is to create a URL query string, and that means name=value pairs, separated by & (or a different separator character of choice.) Commented Jul 16, 2019 at 9:39
  • @misorude What could be the replacement for http_build_query in this case? Commented Jul 16, 2019 at 9:44

2 Answers 2

2

You could use implode():

$server = $_GET["server"];
$data   = [$_GET["z_koord"],
           $_GET['x_koord'],
           $_GET["y_koord"]];
$url    = '.tile.openstreetmap.org';
$saite  = "$server/$url/" . implode('/', $data) . ".png";

I'm not sure about some things in this code, but the implode() should do the job.

Sign up to request clarification or add additional context in comments.

1 Comment

implode() worked just fine for me. Thanks for the suggestion!
1

You are using http_build_query in the wrong way. You just don't need that. There are 2 options, you may use any one of them.

Use implode(), the simplest way to do the job.

$server = array(
    '' => $_GET['server']
);
$data = array(
    $_GET['z_koord'],
    $_GET['x_koord'],
    $_GET['y_koord'],
);
$url   = $server . '.tile.openstreetmap.org';
$saite = $url . '/' . implode("/", $data) . '.png';

Directly create the URL using the Parameters as shown here:

$url   = '.tile.openstreetmap.org' .;
$saite = $_GET['server'] . $url . '/' . $_GET['z_koord'] .'/'. $_GET['x_koord'] . '/'.$_GET['y_koord'] . '.png';

1 Comment

Didn't know about such ways. Thanks for the mentioned options!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.