简体   繁体   English

在php中连接html标签的字符串

[英]concatenate string of html tags in php

I want to build table by concatenating string like this 我想通过串联这样的字符串来构建表
code : 代码

 $html = '';
 $html .="<tr>
            <td>test</td>
            <td>test</td>    
        </tr>";
 $html .="<tr>
            <td>test</td>
            <td>test</td>    
        </tr>";

But I'm getting this as output : 但是我得到这个作为输出

test test 
test test

Instead of table. 而不是表。 What did I miss? 我错过了什么?

EDIT: Forgot to mention that I'm doing this inside of <table> tags 编辑:忘记提及我正在<table>标记内执行此操作

<table>
<tr><td>Col 1</td> <td>Col 2</td> </tr>

  <?
    //concat code
  ?>
</table>

HTML output structure: HTML输出结构:

output 输出

You missed to add <table> tag at start and </table> in end of your html. 您错过了在HTML开头和</table>末尾添加<table>标记的功能。
Do like this 像这样

  $html = '<table>';
  $html .="<tr>
            <td>test</td>
            <td>test</td>    
        </tr>";
  $html .="<tr>
            <td>test</td>
            <td>test</td>    
        </tr>";
  $html .= '</table>';

You forgot to mention border attribute inside table open tag, try below example in order to see table structure in browser. 您忘了在表格打开标签内提及边框属性,请尝试以下示例以查看浏览器中的表格结构。

$html = '<table border="1">';
$html .="<tr>
            <td>test</td>
            <td>test</td>    
        </tr>";
$html .="<tr>
            <td>test</td>
            <td>test</td>    
        </tr>";
$html .= '</table>';

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

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