?
本文檔使用
php中文網(wǎng)手冊(cè) 發(fā)布
印刷術(shù)類提供了幫助您設(shè)置文本格式的方法。
使用印刷類
初始化類
類參考
像CodeIgniter中的大多數(shù)其他類一樣,Typography類在您的控制器中使用以下$this->load->library()
方法進(jìn)行初始化:
$this->load->library('typography');
加載后,Typography庫對(duì)象將可用:
$this->typography
class CI_Typography$protect_braced_quotes = FALSE
將Typography庫與Template Parser庫結(jié)合使用時(shí),通??赡苄枰诖罄ㄌ?hào)內(nèi)保護(hù)單引號(hào)和雙引號(hào)。要啟用此功能,請(qǐng)將protect_braced_quotes
類屬性設(shè)置為TRUE。
用法示例:
$this->load->library('typography');$this->typography->protect_braced_quotes = TRUE;
auto_typography($str[, $reduce_linebreaks = FALSE])
參數(shù): | $ str(string) - 輸入字符串$ reduce_linebreaks(bool) - 是否減少后續(xù)換行符 |
---|---|
返回: | HTML排版安全的字符串 |
返回類型: | 串 |
$ str(string) - 輸入字符串
$ reduce_linebreaks(bool) - 是否減少后續(xù)的換行符
返回:HTML排版安全的字符串
Return type: string
Formats text so that it is semantically and typographically correct HTML. Takes a string as input and returns it with the following formatting:
環(huán)繞<p> </ p>中的段落(尋找雙行換行來標(biāo)識(shí)段落)。
除了那些出現(xiàn)在<pre>標(biāo)簽中的單行換行,單行換行轉(zhuǎn)換為<br />。
塊級(jí)元素(如<div>標(biāo)記)不包含在段落內(nèi),但其包含的文本如果包含段落。
報(bào)價(jià)轉(zhuǎn)換為正確面對(duì)的卷煙報(bào)價(jià)實(shí)體,除了那些出現(xiàn)在標(biāo)簽內(nèi)的報(bào)價(jià)實(shí)體。
撇號(hào)轉(zhuǎn)換為卷曲撇號(hào)實(shí)體。
雙破折號(hào)(或者像這個(gè)或者像這樣)被轉(zhuǎn)換成em-dashes。
在一個(gè)單詞之前或之后的三個(gè)連續(xù)時(shí)間段被轉(zhuǎn)換為省略號(hào)(...)。
句子之后的雙空格轉(zhuǎn)換為非空格來模仿雙空格。
用法示例:
$string = $this->typography->auto_typography($string);
有一個(gè)可選參數(shù),用于確定解析器是否應(yīng)將連續(xù)兩次以上的換行符減少到兩個(gè)。傳遞布爾值TRUE以啟用縮減換行符:
$string = $this->typography->auto_typography($string, TRUE);
注意
印刷格式化可能是處理器密集型的,特別是如果您有很多內(nèi)容被格式化。如果您選擇使用此方法,則可能需要考慮緩存頁面。
format_characters($str)
參數(shù): | $ str(string) - 輸入字符串 |
---|---|
返回: | 格式化的字符串 |
返回類型: | 串 |
$ str(string) - 輸入字符串
返回:格式化的字符串
Return type: string
This method is similar to `auto_typography()` above, except that it only does character conversion:
報(bào)價(jià)轉(zhuǎn)換為正確面對(duì)的卷煙報(bào)價(jià)實(shí)體,除了那些出現(xiàn)在標(biāo)簽內(nèi)的報(bào)價(jià)實(shí)體。
撇號(hào)轉(zhuǎn)換為卷曲撇號(hào)實(shí)體。
雙破折號(hào)(或者像這個(gè)或者像這樣)被轉(zhuǎn)換成em-dashes。
在一個(gè)單詞之前或之后的三個(gè)連續(xù)時(shí)間段被轉(zhuǎn)換為省略號(hào)(...)。
句子之后的雙空格轉(zhuǎn)換為非空格來模仿雙空格。
用法示例:
$string = $this->typography->format_characters($string);
nl2br_except_pre($str)
參數(shù): | $ str(string) - 輸入字符串 |
---|---|
返回: | 格式化的字符串 |
返回類型: | 串 |
$ str(string) - 輸入字符串
Returns: Formatted string
Return type: string
Converts newlines to <br /> tags unless they appear within <pre> tags. This method is identical to the native PHP `nl2br()` function, except that it ignores <pre> tags.
用法示例:
$string = $this->typography->nl2br_except_pre($string);