gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-10-31 23:20:59 25 4
gpt4 key购买 nike

$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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com