gpt4 book ai didi

php - 为什么 php 和 html 混合代码不起作用?

转载 作者:太空宇宙 更新时间:2023-11-04 14:41:48 25 4
gpt4 key购买 nike

我尝试编写这个简单的代码,但它不起作用。这是我的代码...

    <html>
<body>

<?php
$color = "red";
?>

<p>Roses are <?=$color?></p>

</body>
</html>

我将这段代码保存为 new.php它在浏览器窗口中仅显示“Roses are”文本。不打印 $color 的值。我也把它保存为 new.html 但结果是一样的。问题是什么?我做错了什么?

最佳答案

尝试

<html>
<body>

<?php
$color = "red";
?>

<?php echo('<p>Roses are '.$color.'</p>'); ?>

</body>
</html>

<html>
<body>

<?php
$color = "red";
?>

<p>Roses are <?php echo $color; ?></p>

</body>
</html>

关于php - 为什么 php 和 html 混合代码不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14716516/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com