将PHP变量插入HTML表

时间:2016-06-29 17:10:48

标签: php

我是Web开发编程的新手,我试图将PHP变量插入到带有div的HTML表中,但它显示空白

                    <div class="panel-body">
                        <div class="table-responsive">
                            <table class="table table-striped table-bordered table-hover" id="dataTables-example">
                                <thead>

                                    <tr>
                                        <th>sdads</th>
                                        <th>Browser</th>
                                        <th>Platform(s)</th>
                                        <th>Engine version</th>
                                        <th>CSS grade</th>
                                     </tr>

                                </thead>

那不是完整的代码。

如果我想将PHP变量放在<th>sdads</th>所在的位置,我该怎么做? 我试过这个:<th><?php echo $test; ?></th>,但它没有用(变量是在$test="test";的代码开头声明的

2 个答案:

答案 0 :(得分:0)

尝试

<div class="panel-body">
                    <div class="table-responsive">
                        <table class="table table-striped table-bordered table-hover" id="dataTables-example">
                            <thead>

                                <tr>
                                    <th><?php echo $test; ?></th>
                                    <th>Browser</th>
                                    <th>Platform(s)</th>
                                    <th>Engine version</th>
                                    <th>CSS grade</th>
                                 </tr>

                            </thead>

只有一个原因是它不起作用。您在安装PHP时遇到问题,或者您已关闭错误报告。

更改PHP.ini或者如果您是初学者,请下载最新的xmap并安装

答案 1 :(得分:0)

您是否尝试过以下代码?它在我的环境中工作得很好。并且必须使用.php扩展名保存文件。感谢。

    <?php $test = 'sdads'; ?>
    <div class="panel-body">
    <div class="table-responsive">
    <table class="table table-striped table-bordered table-hover" id="dataTables-example">
    <thead>

        <tr>
            <th><?php echo $test; ?></th>
            <th>Browser</th>
            <th>Platform(s)</th>
            <th>Engine version</th>
            <th>CSS grade</th>
         </tr>

    </thead>