Codeigniter Typography Helper – Codeigniter Typography Helper contains functions it will help us Formatting the text in an appropriate manner likes wrapping with paragraphs, convert break line into dash and ellipses. $this->load->helper(‘typography’); is used to load the helper. Here in this tutorial, we are going to explain how to use Typography helper in CodeIgniter.
Codeigniter Typography Helper Example
Let us first see how to load Typography helper in codeigniter and then use its function-
Load Typography Helper
$this->load->helper('typography'); |
Functions:-
There are many functions are available in Typography helper. Now we will explain one by one with example.
- 1. typography-safe string
- 2. formatted line breaks string
- 3. decoded entities string
- $str (string) : Input string
- $reduce_linebreaks (bool) : Whether to reduce multiple instances of double newlines to two
- Returns : HTML-formatted typography-safe string
- Return type : string
- $str (string) : Input string
- Returns : String with HTML-formatted line breaks
- Return type : string
- $str (string) : Input string
- $charset (string) : Character set
- Returns : String with decoded HTML entities
- Return type : string
1. typography-safe string
Syntax of typography-safe string function is
Syntax of typography-safe string function is:-
auto_typography($str[$reduce_linebreaks = FALSE]) |
Parameters:
EXAMPLE
Here is simple example of typography-safe string.
typography-safe string in Codeigniter Example:-
//Controllers part public function typographyCheck() { $this->load->helper('typography'); $this->load->view('typography_view'); } // Views parts <?php $string = "This is a\n\nstring!"; $string = auto_typography($string); echo $string; ??> |
This Helper Convert New Lines to Paragraph
The output will be like this –
2. formatted line breaks string
Syntax of formatted line breaks string function is
Syntax of formatted line breaks string function is:-
nl2br_except_pre($str) |
Parameters:
EXAMPLE
Here is simple example of formatted line breaks string.
formatted line breaks string in Codeigniter Example:-
// Views parts <?php $string = "Hello \n\nSolidCoupon!"; $string = nl2br_except_pre($string); echo $string; ??> |
This Helper Convert New Lines to Break Lines
The output will be like this –
3. decoded entities string
Syntax of decoded entities string function is
Syntax of decoded entities string function is:-
entity_decode($str, $charset = NULL) |
Parameters:
EXAMPLE
Here is simple example of decoded entities string.
decoded entities string in Codeigniter Example:-
// Views parts |
The output will be like this –