排版辅助函数
这个排版辅助函数文件里的函数能够让你按照相关词性对文本的格局进行排版。
载入这个辅助函数
请使用如下代码载入这个辅助函数:
$this->load->helper('typography');
以下函数可以使用:
auto_typography()
Formats text so that it is semantically and typographically correct HTML. 接收一个字符串,它可以返回以下的格式:
- 每个段落都会放在 <p></p> 里(双换行来突出段落)。
- 单换行会转化成 <br />, 除非它在这样的标记符 <pre> 里。
- Block level elements, like <div> tags, are not wrapped within paragraphs, but their contained text is if it contains paragraphs.
- Quotes are converted to correctly facing curly quote entities, except those that appear within tags.
- Apostrophes are converted to curly apostrophy entities.
- Double dashes (either like -- this or like--this) are converted to em—dashes.
- Three consecutive periods either preceding or following a word are converted to ellipsis…
- Double spaces following sentences are converted to non-breaking spaces to mimic double spacing.
例子:
$string = auto_typography($string);
注意: 排版格式可能会增加处理器的负荷,特别是当你有大量的内容需要被处理时。 如果选择使用这个函数的话,你可能需要考虑缓存你的页面。
nl2br_except_pre()
如果换行不在标记符 <pre> 里的话,都会被转换成 <br /> 标记符。这个函数除了会忽略标记符<pre> 以外,和PHP自带函数nl2br()是相等的。
例子:
$string = nl2br_except_pre($string);
翻译贡献者:
aykirk, Hex
最后修改: 2008-09-05 00:18:01