php - tidy_repair_string 删除结束换行符(\n 或\r)

标签 php htmltidy

$HTMLcodeOutput = tidy_repair_string($HTMLcode, array('show-body-only' => true, 'indent' => true));

将删除 $HTMLcode' 行尾。 例如:

that's in the main box



##What does it do ?

it does everything



##Output:

会输出

that's in the main box ##What does it do ? it does everything
##Output: I will giv ea a grat output

如果此字符串之后没有回显到

 标记中,这将不是问题。因此,\n 或\r 字符很重要。
我查看了文档,但找不到任何明显的内容。

有什么办法可以保留这些换行符吗?

(在使用 tidy string repair 之前添加标签是个坏主意,因为它会导致

 标签在浏览器中可见,作为字符串(已解码)而不是标签。)

最佳答案

如果我没理解错的话,您正在尝试格式化 html 以提高人类可读性,并且您不想使用“pre”标签来强制 tidy 保留空白,因为您之前将通过 htmlspecialchars 运行 tidy 的输出将其输出到浏览器。

为什么不在清洁后删除那些“pre”标签?它看起来像这样:

$config = array('show-body-only' => true, 'indent' => true);
$HTMLcodeOutput = tidy_repair_string('<pre>'.$HTMLcode.'</pre>', $config);
$HTMLcodeOutput = substr($HTMLcodeOutput, 5, -6);

关于php - tidy_repair_string 删除结束换行符(\n 或\r),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20331299/

相关文章:

javascript - 使用类元素和 Javascript 进行线钳位

php - Laravel 质量分配不插入 bool 值

php - Bash sanitize_file_name 函数

有趣的是,libtidy 抛出的 Python 异常无法捕获

开始时的 HTML Tidy 剥离空间

PHP:html 整洁修复字符串:使其不包含 <html> 中的所有内容

HTML 整洁。请不要添加结束标签

php - 致命的 : unable to update url base from redirection

php - 如何根据当前页面/网址获得 ="selected"类

html - 使用 HTML Tidy 来缩进 HTML 代码?