Ten*_*eno 2 html php formatting html-parsing
在PHP中显示HTML代码时,如果我想缩进标签最好的方法是什么?
例如,
<?php
$html = '<div><p><span>some text</span></p></div>';
echo htmlspecialchars($html);
?>
Run Code Online (Sandbox Code Playgroud)
会给<div><p><span>some text</span</p></div>.
相反,我想表现出类似的东西,
<div>
<p>
<span>some text</span>
</p>
</div>
Run Code Online (Sandbox Code Playgroud)
你可以使用htmLawed
http://www.bioinformatics.org/phplabware/internal_utilities/htmLawed/
这将是你的代码:
<?php
require("htmLawed/htmLawed.php");
echo "<pre>";
echo htmlspecialchars(
htmLawed('<div><p><span>some text</span></p></div>', array('tidy'=>4))
);
echo "</pre>";
?>
Run Code Online (Sandbox Code Playgroud)