PHP将echo和html一起使用 [英] PHP echo variable and html together

查看:106
本文介绍了PHP将echo和html一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这是一个基本的php问题,但是我无法在HTML回显中显示变量.以下是我要实现的目标.

I know this is a basic php question, but I'm having trouble showing variables inside an echo of HTML. Below is what I'm trying to achieve.

<?php
    $variable = 'testing';
    echo <span class="label-[variable]">[variable]</span>
?>

应输出:

<span class="label-testing">testing</span>

推荐答案

<?php
    $variable = 'testing';
    echo <span class="label-[variable]">[variable]</span>
?>

应该是

<?php
    $variable = 'testing';
    echo '<span class="label-' . $variable .'">' . $variable . '</span>';
?>

这篇关于PHP将echo和html一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆