我的代码是这样的
<?php
ob_start();
?>
....
Some HTML
...
<div class="ui-state-error ui-corner-all" style="padding: 0 .7em;">
<p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span>
<strong>Alert:</strong> Sample ui-state-error style.</p>
</div>
....
Some HTML
...
<?php
$markup = ob_get_clean();
// Specify configuration
$config = array(
'indent' => true,
'output-xhtml' => true,
'wrap' => 200);
// Tidy
$tidy = new tidy;
$tidy->parseString($markup, $config, 'utf8');
$tidy->cleanRepair();
// Output
echo $tidy;
?>
在没有 <span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span>
的情况下得到结果.我错过了什么?也许 TIDY 类删除空标签?如果是,我该如何预防?
最佳答案
我发表了评论:“您是否尝试过在 span 中添加
或一些文本以确保将其删除,因为它是空的?”。看起来
起作用了。
所以如果有人遇到同样的问题来到这里,解决方案是:
在空元素中添加
。
关于PHP 整洁地删除 <span>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12236345/