Php 如何将变量作为查询正确地附加到链接?

Php 如何将变量作为查询正确地附加到链接?,php,wordpress,Php,Wordpress,我正在使用Wordpress插件,它向用户发送通知电子邮件。在这样一封电子邮件中,我知道我想嵌入一个ahref链接,它将某些变量作为查询参数传递 目前我在插件中使用了两个变量: $email (the email address of the user) $scheduler->post (the name of the post, from which a user has activated the notification plugin) 现在我想创建一个ahref链接,它将这两个

我正在使用Wordpress插件,它向用户发送通知电子邮件。在这样一封电子邮件中,我知道我想嵌入一个ahref链接,它将某些变量作为查询参数传递

目前我在插件中使用了两个变量:

$email (the email address of the user)
$scheduler->post (the name of the post, from which a user has activated the notification plugin)
现在我想创建一个ahref链接,它将这两个变量附加到URL,这样我就可以在用户单击链接时指向的表单中访问它们

目的是创建如下URL:

www.website.com/form?email=example@example.com&postname=example
我怎样才能做到这一点?URL应该是什么样子

像这样

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

谢谢你的帮助


Alexander

在添加到URL之前,应先转义变量。PHP包含使用数组中的变量构建查询字符串的函数,示例用法:

$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 this link</a>';
$email=”example@example.com';
$postname='postname';
$url='1http://www.example.com/';
$queryString=http\u生成\u查询(数组(
“email”=>$email,
“postname”=>$postname
));
$link='';

另请参阅PHP的函数,它可以用来代替http\u build\u query()