JYuk
JYuk

Reputation: 5

Constructing a URL based on existing variables

I'm a bit of a PHP newbie, and I'm trying to do what I believe is quite a complicated operation on a website. So I need your help :)

What I want to do is request a specific page for each client, the only URL variables involved are at the end, as normal.

Basically my variables have been set previously in the script, what I want to say is; The URL is http://site.com/index.php?image=$clientnumber Somehow.

if you guys could give me some insight on how to do this, that would be great!

Upvotes: 0

Views: 69

Answers (3)

user399666
user399666

Reputation: 19879

$data = array('foo'=>'bar',
              'baz'=>'boom',
              'cow'=>'milk',
              'php'=>'hypertext processor');

echo http_build_query($data) . "\n";

Results in:

foo=bar&baz=boom&cow=milk&php=hypertext+processor

For your needs:

$data = array('image'=> $clientnumber);
echo 'index.php?' . $data;

Will give you:

index.php?image=878787283

Upvotes: 0

alexbusu
alexbusu

Reputation: 741

PHP String Operators

$new_url = "http://site.com/index.php?image=$clientnumber";

or

$new_url = 'http://site.com/index.php?image=' . $clientnumber;

Upvotes: 1

JvdBerg
JvdBerg

Reputation: 21856

You can use the sprintf function to do this:

$url = sprintf('http://site.com/index.php?image=%s', $clientnumber);

Upvotes: 1

Related Questions