I am trying to grab a parameter from a webpage and insert it into a URL link on that same page but am having problems with the syntax.
So, for example, the webpage is www.website.com?src=mm
Currently the code on the page that does not pull in the parameter is
<?php echo "<A HREF='http://www.website2.com?offer=AAt&sub1=422'><B>Click Here</B></A><BR>" ?>
I would like to include that "mm" parameter at the end of the URL so the final URL is:
http://www.website2.com?offer=AA&sub1=422&sub2=mm
I tried the following but does not work:
<?php echo "<A HREF='http://www.website2.com?offer=AA&sub1=422&sub2='.$_GET['src']."><B>Click Here</B></A><BR>" ?>
Any ideas on how to get this to work? Thanks
答案 0 :(得分:0)
您的代码甚至无法编译:
Parse error: syntax error, unexpected 'http' (T_STRING), expecting ',' or ';' in /var/www/html/ImagePT/test.php on line 1
必须是
<?php echo '<A HREF="http://www.website2.com?offer=AA&sub1=422&sub2='.$_GET['src'].'"><B>Click Here</B></A><BR>'; ?>
但是由于我只是想给您一些进一步的建议:
您不必大写HTML,这是很不寻常的(不是不可能,但您不会经常看到它)-然后,当$_GET['src']
变量未定义时,此脚本很可怕。我会检查它是否已设置,然后相应地修改URL。所以我的建议是使用以下内容:
<?php
if(isset($_GET['src']))
{
echo '<a href="http://www.website2.com?offer=AA&sub1=422&sub2='.$_GET['src'].'"><b>Click Here</b></a></br>';
}
else
{
echo '<a href="http://www.website2.com?offer=AA&sub1=422"><b>Click Here</b></a></br>';
}
?>