简体   繁体   English

<tr>和<td>标签覆盖<pre>

[英]<tr> and <td> tags overwriting <pre>

Is there a reason why <tr> and <td> tags would work whilst inside a <pre> tag? <tr><td>标签在<pre>标签内可以工作是否有原因?

I am using a <pre> tag to show some PHP code on a website and within the code are various instances of the html tags <tr> and <td> , these are jumping out of the <pre> tags and executing at the bottom.我正在使用<pre>标签在网站上显示一些 PHP 代码,在代码中是 html 标签<tr><td>各种实例,它们跳出<pre>标签并在底部执行. Why would they do this??他们为什么要这样做??

They are included after echo and inside "" and '' and both are executing the same.它们包含在echo之后和内部 "" 和 '' 中,并且两者都执行相同的操作。 I have no pre in my CSS and can't find any similar problems on the net.我的 CSS 中没有pre并且在网上找不到任何类似的问题。

Example:例子:

echo '<table border="1">';
echo "<tr><td>A</td><td>B</td><td>C</td><td>D</td><td>E</td></tr>";
while($info = mysql_fetch_array($data)){
echo "<tr>";
echo "<td>" . $info['a'] . "</td>";
echo "<td>" . $info['b'] . "</td>"; 
echo "<td>" . $info['c'] . "</td>";
echo "<td>" . $info['d'] . "</td>";
echo "<td>" . $info['e'] . "</td>";
echo "</tr>";
};
echo "</table>";

I have tried using print , no change我试过使用print ,没有变化

You have to encode the < and > as HTML entities.您必须将<>编码为 HTML 实体。

https://mothereff.in/html-entities https://mothereff.in/html-entities

https://html.spec.whatwg.org/multipage/named-characters.html#named-character-references https://html.spec.whatwg.org/multipage/named-characters.html#named-character-references

so < would be &lt;所以<将是&lt; and > would be &gt;并且>将是&gt;

I think the specific use of <pre> tag is to display the element as what is it, even non- &nbsp;我认为<pre>标签的具体用途是将元素显示为它是什么,即使是非&nbsp; multiple spaces will be display, nor a breakline by a keyboard (non- <br /> tag) , and not to fail a HTML tag.将显示多个空格,也不会显示键盘的分隔线(非<br />标签) ,并且不会使 HTML 标签失败。 You can use this format &lt;tag> to fail a tag.您可以使用这种格式&lt;tag>来使标记失败。 But I didn't know if <pre> can fails a PHP code.但我不知道<pre>可以使 PHP 代码失败。

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

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