繁体   English   中英

在 HTML 中的 php 中连接

[英]Concatenate in php inside HTML

我无法连接我不太擅长它想知道在这种情况下我将如何连接

<?php   $id = getfield('id'); ?>// this is a function to get fields from sql

<html>
    <?php <a class="profile" href="profile.php?='$id' ">
<echo ucfirst ($firstname);</a> ?>//i cant seem to get this part
    </html>

这是我到目前为止所尝试的我确实尝试了一些其他方法来做到这一点,但它们似乎都不起作用

这可能是您正在寻找的:

<?php $id = getfield('id'); ?> // this is a function to get fields from sql

<html>
    <a class="profile" href="profile.php?id=<?php echo $id ?>">
        <?php echo ucfirst ($firstname) ?>
    </a>
</html>

或者,如果您在 php 中启用了“短标签”,则更紧凑:

<?php $id = getfield('id'); ?> // this is a function to get fields from sql

<html>
    <a class="profile" href="profile.php?id=<?= $id ?>">
        <?= ucfirst ($firstname) ?>
    </a>
</html>

最后你可以内联赋值,因为变量只使用一次:

<html>
    <a class="profile" href="profile.php?id=<?= getfield('id') ?>">
        <?= ucfirst ($firstname) ?>
    </a>
</html>

这应该可以解决问题:

<?php
  $id = getfield('id'); // this is a function to get fields from sql


    echo '<html>
             <a class="profile" href="profile.php?='.$id.' ">'.ucfirst ($firstname).'</a>
         </html>';
?>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM