The Typography library contains methods that help you format text in semantically relevant ways.
Like all services in CodeIgniter, it can be loaded via Config\Services, though you usually will not need to load it manually:
$typography = \Config\Services::typography();
The following functions are available:
autoTypography($str[, $reduce_linebreaks = false]) | Parameters: |
|
|---|---|
| Returns: |
HTML-formatted typography-safe string |
| Return type: |
string |
Formats text so that it is semantically and typographically correct HTML.
Usage example:
$string = $typography->autoTypography($string);
Note
Typographic formatting can be processor intensive, particularly if you have a lot of content being formatted. If you choose to use this function you may want to consider caching your pages.
formatCharacters($str) | Parameters: |
|
|---|---|
| Returns: |
String with formatted characters. |
| Return type: |
string |
This function mainly converts double and single quotes to curly entities, but it also converts em-dashes, double spaces, and ampersands.
Usage example:
$string = $typography->formatCharacters($string);
nl2brExceptPre($str) | Parameters: |
|
|---|---|
| Returns: |
String with HTML-formatted line breaks |
| Return type: |
string |
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 = $typography->nl2brExceptPre($string);
© 2014–2020 British Columbia Institute of Technology
Licensed under the MIT License.
https://codeigniter.com/user_guide/libraries/typography.html