我似乎无法在没有错误的情况下向 URL 添加目标:/ 有人可以帮忙吗?谢谢!
<?php
echo "<a href=\"".$banner[$random]['link']."\"><img src=\"".$banner[$random]['img']."\" border=\"0\"></a>";
//result
?>
我试过这个解决方案;
echo "<a href=\"".$banner[$random]['link']."\"><img src=\"".$banner[$random]['img']."\" border=\"0\".'" target="_blank"></a>";
这是完整的代码(它是一个随机图像 + URL 脚本):
<?php
$banner[1]['link'] = "http://www.url.com";
$banner[1]['img'] = "/banners/square_1.jpg";
$banner[2]['link'] = "http://url.com";
$banner[2]['img'] = "/banners/square_2.jpg";
//number of banners
$banners=2;
srand((double)microtime()*1000000);
$random = rand(1,$banners);
echo "<a href=\"".$banner[$random]['link']."\"><img src=\"".$banner[$random]['img']."\" border=\"0\"></a>";
//result
?>