我想传递一个php变量作为链接的一部分。我如何才能做到这一点?
$x = 24; //$x is a php variable 如何将此值作为href="“的一部分传递。一个有效的例子会很有帮助。
发布于 2011-01-18 07:15:59
<A href="whatever.php?x=<php echo $x;?>">link</a>发布于 2011-01-18 07:18:23
它的工作原理很像你从Javascript中知道的版本:
print '<a href="page.php?x=' . urlencode($x) . '&y=2">click here</a>';或者,如果您想使用PHP内联html表示法样式(启用短标记<?= ):
<p><a href="page.php?x=<?= urlencode($x) ?>">click here</a></p>发布于 2011-01-18 07:20:07
$x = 24;
$y = 'some text';
print('<a href="http://site.com/url.php?x=' . rawurlencode($x) . '&y=' . rawurlencode($y) . '"></a>');在url.php文件中,您可以使用以下命令获取此变量
$x = $_GET['x'];
$y = $_GET['y'];https://stackoverflow.com/questions/4718909
复制相似问题