Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在html表中使用html字符回显文本_Php_Html - Fatal编程技术网

Php 在html表中使用html字符回显文本

Php 在html表中使用html字符回显文本,php,html,Php,Html,我需要打印一个带有HTML字符的字符串,如。 当它需要打印空格时,比如标签。 所以我有这个代码: $descricao = str_replace("%q", " < ", str_replace("%w", " > ", str_replace("%s", "<br />", preg_replace

我需要打印一个带有HTML字符的字符串,如。 当它需要打印空格时,比如标签。 所以我有这个代码:

$descricao = str_replace("%q", " < ",
                          str_replace("%w", " > ",
                             str_replace("%s", "<br />",
                               preg_replace('/(\<)/', '%q',
                                 preg_replace('/(\>)/', '%w',
                                     preg_replace('/(\<br \/\>)/', '%s', $pr->descricao)
                                     )
                                 )
                               )
                             )
                         );
这很好,但很混乱。 你有简短易读的东西吗

例如:

$string = "Lorem ipsum dolor sit amet, <br /> <consectetur>";
<table>
  <tr><td>echo $string</td></tr>
</table>
我需要这样表现

Lorem ipsum dolor sit amet,
<consectetur>
试试这个:

$string = "Lorem ipsum dolor sit amet, <br /> <consectetur>";

$string = str_replace("\n", "<br />", 
                    htmlentities(
                        str_replace("<br />", "\n", $string)
                    ) 
                ); 

echo $string;

完美的我只是将htmlspecialchars更改为htmlspecialchars。