Typography 類?
Typography 庫(kù)包含一些方法用于幫助您以語(yǔ)義相關(guān)的方式設(shè)置文本格式。
加載類庫(kù)?
與 CodeIgniter 的所有其他服務(wù)一樣,可以通過 Config\Services
來(lái)加載,通常不需要手動(dòng)加載:
$typography = \Config\Services::typography();
可用的靜態(tài)方法?
以下的方法是可用的:
autoTypography()
-
autoTypography
($str[, $reduce_linebreaks = FALSE])? 參數(shù): - $str (string) – Input string
- $reduce_linebreaks (bool) – 是否將多個(gè)雙重?fù)Q行減少為兩個(gè)
返回: HTML 格式化的排版安全的字符串
返回類型: string
格式化文本使其成為語(yǔ)義和排版正確的 HTML 。
使用示例:
$string = $typography->autoTypography($string);
注解
格式排版可能會(huì)消耗大量處理器資源,特別是在排版大量?jī)?nèi)容時(shí)。 如果你選擇使用這個(gè)函數(shù)的話, 你可以考慮 緩存 你的頁(yè)面。
formatCharacters()
-
formatCharacters
($str)? 參數(shù): - $str (string) – Input string
返回: 帶有格式化字符的字符串
返回類型: string
將雙引號(hào)或單引號(hào)轉(zhuǎn)成正確的實(shí)體,也會(huì)轉(zhuǎn)化—破折號(hào),雙空格和&符號(hào)。
使用示例:
$string = $typography->formatCharacters($string);
nl2brExceptPre()
-
nl2brExceptPre
($str)? 參數(shù): - $str (string) – Input string
返回: 帶有 HTML 格式化換行符的字符串
返回類型: string
將換行轉(zhuǎn)換為 <br /> 標(biāo)簽, 忽略 <pre> 標(biāo)簽中的換行符。 這個(gè)函數(shù)和PHP原生的
nl2br()
函數(shù)是一樣的, 但忽略 <pre> 標(biāo)簽。使用示例:
$string = $typography->nl2brExceptPre($string);