使 PHP 变量成为链接

make a PHP variable a link

本文关键字:链接 变量 PHP      更新时间:2023-12-18

>有谁知道如何从 php 变量中建立链接。 我希望我的 php 变量$LeagueLink是指向 leaguehome 的链接,其中包含 mysql 查询结果的名称。 如果可以的话,请帮忙。

$result = mysql_query("SELECT League FROM League_Info WHERE User_ID = '$id'");
$result2 = mysql_fetch_array($result);
    $result3 = $result2['League'];
    $LeagueLink = '<a href="home.com/test.php"><?=$result3?></a>';
$LeagueLink = "<a href='"http://home.com/leaguehome.php'">$result3</a>";

要将变量直接放入上面的字符串中,它需要是一个双引号字符串("(,而不是单引号字符串(' (

或者,如果您担心粗心引起的错误,请使用字符串串联:

$LeagueLink = '<a href="http://home.com/leaguehome.php">' . $result3 . '</a>';

你也可以这样做

$LeagueLink = '<a href="home.com/leaguehome.php">'.$result3.'</a>';