排版辅助库

排版辅助库文件包含了文本排版相关的一些函数。

加载辅助库

该辅助库通过下面的代码加载:

$this->load->helper('typography');

可用函数

该辅助库有下列可用函数:

auto_typography($str[, $reduce_linebreaks = FALSE])
Parameters:
  • $str (string) – Input string
  • $reduce_linebreaks (bool) – Whether to reduce multiple instances of double newlines to two
Returns:

HTML-formatted typography-safe string

Return type:

string

格式化文本以便纠正语义和印刷错误的 HTML 代码。

这个函数是 CI_Typography::auto_typography 函数的别名。 更多信息,查看 排版类

Usage example:

$string = auto_typography($string);

Note

格式排版可能会消耗大量处理器资源,特别是在排版大量内容时。 如果你选择使用这个函数的话,你可以考虑使用 缓存 <../general/caching>

nl2br_except_pre($str)
Parameters:
  • $str (string) – Input string
Returns:

String with HTML-formatted line breaks

Return type:

string

将换行符转换为 <br /> 标签,忽略 <pre> 标签中的换行符。除了对 <pre> 标签中的换行处理有所不同之外,这个函数和 PHP 函数 nl2br() 是完全一样的。

使用示例:

$string = nl2br_except_pre($string);
entity_decode($str, $charset = NULL)
Parameters:
  • $str (string) – Input string
  • $charset (string) – Character set
Returns:

String with decoded HTML entities

Return type:

string

这个函数是 CI_Security::entity_decode() 函数的别名。 更多信息,查看 安全类