多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
# 排版类 排版类提供了一些方法用于帮助你格式化文本。 * [使用排版类](http://codeigniter.org.cn/user_guide/libraries/typography.html#id2) * [初始化该类](http://codeigniter.org.cn/user_guide/libraries/typography.html#id3) * [类参考](http://codeigniter.org.cn/user_guide/libraries/typography.html#id4) ## [使用排版类](http://codeigniter.org.cn/user_guide/libraries/typography.html#id5) ### [初始化该类](http://codeigniter.org.cn/user_guide/libraries/typography.html#id6) 跟 CodeIgniter 中的其他类一样,可以在你的控制器中使用 $this->load->library() 方法加载排版类: ~~~ $this->load->library('typography'); ~~~ 一旦加载,排版类就可以像下面这样使用: ~~~ $this->typography ~~~ ## [类参考](http://codeigniter.org.cn/user_guide/libraries/typography.html#id7) classCI_Typography $protect_braced_quotes = FALSE 当排版类和 [模板解析器类](http://codeigniter.org.cn/user_guide/libraries/parser.html) 同时使用时,经常需要保护大括号中的的单引号和双引号不被转换。 要保护这个,将 protect_braced_quotes 属性设置为 TRUE 。 使用示例: ~~~ $this->load->library('typography'); $this->typography->protect_braced_quotes = TRUE; ~~~ format_characters($str) 参数: * **$str** (string) -- Input string 返回: Formatted string 返回类型: string 该方法和上面的 auto_typography() 类似,但是它只对字符进行处理: > > > * 除了出现在标签中的引号外,引号会被转换成正确的实体。 > * 撇号被转换为相应的实体。 > * 双破折号(像 -- 或--)被转换成 em — 破折号。 > * 三个连续的点也会被转换为省略号… 。 > * 句子后连续的多个空格将被转换为   以便在网页中显示。 > > 使用示例: ~~~ $string = $this->typography->format_characters($string); ~~~ nl2br_except_pre($str) 参数: * **$str** (string) -- Input string 返回: Formatted string 返回类型: string 将换行符转换为 标签,忽略 标签中的换行符。除了对 标签中的换行处理有所不同之外,这个函数和 PHP 函数 nl2br() 是完全一样的。 使用示例: ~~~ $string = $this->typography->nl2br_except_pre($string); ~~~