Thursday 15 September 2011

php - How to correctly append variables to a link as a query? -



php - How to correctly append variables to a link as a query? -

i using wordpress plugin, sends users notification emails. within such email, know want embed ahref link, passes variables query parameter.

currently utilize 2 variables in plugin:

$email (the email address of user) $scheduler->post (the name of post, user has activated notification plugin)

i want create ahref link, appends both variables url, can access them in form users beingness directed when clicking link.

the aim create url this:

www.website.com/form?email=example@example.com&postname=example

how can accomplish this? how should url like?

like this?

<a href="http://www.example.com/?email=$email&postname=$scheduler->post">visit link</a>

thanks help.

alexander

you should escape variables before adding url. php includes http_build_query() function build query string using variables in array, illustration usage:

$email = 'example@example.com'; $postname = 'postname'; $url = 'http://www.example.com/'; $querystring = http_build_query(array( 'email' => $email, 'postname' => $postname )); $link = '<a href="' . $url . . '?' . $querystring . '">visit link</a>';

also see php's urlencode() function used instead of http_build_query().

php wordpress

No comments:

Post a Comment