【问题标题】:HTML - PHP - Trying to inert a variable in <a href=>HTML - PHP - 试图惰性化 <a href=> 中的变量
【发布时间】:2020-07-01 18:32:29
【问题描述】:

我从 SQL 数据库中获取一个变量 - 并希望将其添加到 HTML 标记中。

虽然变量在那里 - echo 语句不喜欢我插入的 PHP 并且总是炸弹!

<?php
$field = "Folder2";
if ($field == $field){
        echo('<a href="/folder1/<?php echo $field ?>">123</a><br>
            ');
    }
?>

这总是返回 - https://website.com/folder1/%3C?php%20echo%20$field%20?%3E

这是:https://website.com/folder1/

我是新手,所以它肯定只是一个错字或撇号 - 但非常感谢任何帮助

【问题讨论】:

    标签: php html echo


    【解决方案1】:

    您是否尝试在代码 &lt;?php 中打开另一个 &lt;?php 你只需要使用连接。使用

    <?php
        $field = "Folder2";
        if ($field == $field){
            echo '<a href="/folder1/'.$field.'">123</a><br>';
        }
    ?>
    

    【讨论】:

    • 非常感谢 - 效果很好!也是第一次!!不能投票给你,因为我还是初级会员 - Grrr!!
    【解决方案2】:

    您正在尝试在 PHP 中打印

    试试这个

    <?php
    $field = "Folder2";
    if ($field == $field){
    echo "<a href=\"/folder1/$field\">123</a><br>";
    }
    ?>
    

    或

    <?php
    $field = "Folder2";
    if ($field == $field){
    ?>
    <a href="/folder1/<?php echo $field; ?>">123</a><br>
    <?php
    }
    ?>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-03-18
      • 1970-01-01
      • 1970-01-01
      • 2014-10-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多