CodeIgniter 用户指南 版本 2.0.0

PHP100中文网
查看原文

排版类

排版类提供帮助你格式化文本的函数。

初始化排版类

和CI中的其他类一样, 排版类也需要在控制器中这样用 $this->load->library 方法初始化:

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

一旦被加载, 排版类的对象就可以这样使用: $this->typography

auto_typography()

格式化文本以便纠正语义和印刷的错误HTML代码。输入一个字符串输出如下的格式化文本:

例如:

$string = $this->typography->auto_typography($string);

参数

有一个可选参数:布尔值 TRUEFALSE决定是否对超过两个的换行进行压缩,减少到两行。

默认不压缩. 也就是说, 如果这个参数不设置, 它将如下工作:

$string = $this->typography->auto_typography($string, FALSE);

提示: 排版格式化可以处理密集数据, 特别是你有很多内容需要格式化处理。如果你选择这个函数处理,你可以考虑缓存你的网页。

format_characters()

This function is similar to the auto_typography function above, except that it only does character conversion:

Usage example:

$string = $this->typography->format_characters($string);

nl2br_except_pre()

Converts newlines to <br /> tags unless they appear within <pre> tags. This function is identical to the native PHP nl2br() function, except that it ignores <pre> tags.

Usage example:

$string = $this->typography->nl2br_except_pre($string);

protect_braced_quotes

When using the Typography library in conjunction with the Template Parser library it can often be desirable to protect single and double quotes within curly braces. To enable this, set the protect_braced_quotes class property to TRUE.

Usage example:

$this->load->library('typography');
$this->typography->protect_braced_quotes = TRUE;

 

翻译贡献者: Hex, icebird, neversaylate, tonera
最后修改: 2011-02-01 02:03:41