show.html中换行显示:nl2br($字段名)套用 迅睿框架 更新 2025-09-15 10:42:01 towe 多行文本Textarea内容详情中(show.html) 模板中调用方法:换行显示:{nl2br($字段名)}按照换行显示输出后如何定义每一行的样式?比如把字体设为H2,颜色设为红色我套了样式无法生效是怎么回事?代码.txt
/** * 将多行文本的每一行(忽略空行)用 <p> 标签包裹 * @param string $text 原始文本 * @param bool $skipEmpty 是否跳过空行,默认 true * @return string */ function my_nl2p(string $text, bool $skipEmpty = true): string { // 统一换行符,避免 Windows/Unix 混用 $text = str_replace(["\r\n", "\r"], "\n", $text); // 拆成数组 $lines = explode("\n", $text); $html = ''; foreach ($lines as $line) { if ($skipEmpty && trim($line) === '') { continue; } // 转义 HTML 特殊字符,保持内容原样 $html .= '<p>' . htmlspecialchars($line, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8') . '</p>' . PHP_EOL; } return $html; }将以上代码 放在 自定义函数文件:config/custom.php {my_nl2p($字段名)}