如何在echo中使用PHP变量?

时间:2014-09-09 01:00:09

标签: php echo

所以,我有这个PHP变量:

$text = 'Click on this';

echo '< a href="Google.com"> $text < /a>'

我如何拥有&#34;点击此处&#34;作为超链接文本?

到目前为止,输出在HTML中显示为$ text。

1 个答案:

答案 0 :(得分:4)

两个错误:

  1. 缺少分号
  2. 变量在单引号内插值。在字符串中使用双引号或其他方法来放置变量。
  3. 示例:

    $text = 'Click on this';
    echo "<a href=\"Google.com\"> $text </a>";
    

    $text = 'Click on this';
    echo '<a href="Google.com"> ', $text, ' </a>';
    

    $text = 'Click on this';
    echo '<a href="Google.com"> ' . $text . ' </a>';
    

    $text = 'Click on this';
    printf('<a href="Google.com"> %s </a>', $text);