Codeigniter Text Helper
Codeigniter Text Helper – Codeigniter text helper contains functions it will help us to do work with string. it has word limiter, character limiter and lots of function.$this->load->helper(‘text’); is used to load the helper. Here in this tutorial, we are going to explain how to use text helper in codeIgniter.
Codeigniter Text Helper Example
Let us first see how to load text helper in codeigniter and then use its function-
Load text helper
How to load text helper in codeingniter example:
$this->load->helper('text'); |
Functions:-
There are many functions available in text helper. Now we will explain one by one with example.
- 1. Word-limited string
- 2. Character-limited string
- 3. ASCII values converted to entities
- 4. accented characters converted
- 5. Censored string
- 6. highlighted code string
- 7. highlighted phase string
- 8. Word-wrapped string
- 9. Ellipsized string
- $str (string) : Input string
- $limit (int) : Limit
- $end_char (string) : End character (usually an ellipsis)
- Returns : Word-limited string
- Return type : string
- $str (string) : Input string
- $n (int) : Number of characters
- $end_char (string) : End character (usually an ellipsis)
- Returns : Character-limited string
- Return type : string
- $str (string) : Input string
- Returns : A string with ASCII values converted to entities
- Return type : string
- $str (string) : Input string
- Returns : A string with accented characters converted
- Return type : string
- $str (string) : Input string
- $censored (array) : List of bad words to censor
- $replacement (string) : What to replace bad words with
- Returns : Censored string
- Return type : string
- $str (string) : Input string
- Returns : String with code highlighted via HTML
- Return type : string
- $str (string) : Input string
- $phrase (string) : Phrase to highlight
- $tag_open (string) : Opening tag used for the highlight
- $tag_close (string) : Closing tag for the highlight
- Returns : String with a phrase highlighted via HTML
- Return type : string
- $str (string) : Input string
- $charlim (int) : Character limit
- Returns : Word-wrapped string
- Return type : string
- $str (string) : Input string
- $max_length (int) : String length limit
- $position (mixed) : Position to split at (int or float)
- $ellipsis (string) : What to use as the ellipsis character
- Returns : Ellipsized string
- Return type : string
1. Word-limited string
Syntax of Word-limited string function is
Syntax of Word-limited string function is:-
word_limiter($str[$limit = 100[$end_char = '…']]) |
Parameters:
This Function is remove extra word to the number of words specified.
EXAMPLE
Here is simple example of word-limited string.
Word-limited string in codeigniter example:-
//Controllers part public function textCheck() { $this->load->helper('text'); $this->load->view('text_view'); } // Views parts <?php $string = "Welcome To SolidCoupon |Solid COupon."; $string = word_limiter($string, 3); echo $string; ?> |
The output will be like this –
2. Character-limited string
Syntax of character-limited string function is
Syntax of character-limited string function is:-
character_limiter($str[$n = 500[$end_char = '…']]) |
Parameters:
This Function is remove extra characters to the number of characters specified.
EXAMPLE
Here is simple example of character-limited string.
Character-limited string in codeigniter example:-
// Views parts <?php $string = "Wecome to solid coupon and tutorials plane."; $string = character_limiter($string, 25); echo $string; ?> |
The output will be like this –
3. ASCII values converted to entities
Syntax of ASCII values converted to entities function is
Syntax of ASCII values converted to entities function is:-
ascii_to_entities($str) |
Parameters:
EXAMPLE
Here is simple example of ASCII values converted to entities.
ASCII values converted to entities in codeigniter example:-
// Views parts <?php $string = "Wecome to solid coupon and tutorials plane."; echo ascii_to_entities($string); ?> |
The output will be like this –
4. accented characters converted
Syntax of accented characters converted function is
Syntax of accented characters converted function is:-
convert_accented_characters($str) |
Parameters:
EXAMPLE
Here is simple example of accented characters converted.
Accented characters converted in codeigniter example:-
// Views parts <?php $string = "Wecome to solid coupon and tutorials plane."; echo convert_accented_characters($string); ?> |
The output will be like this –
5. Censored string
Syntax of censored string function is
Syntax of censored string function is:-
word_censor($str, $censored[$replacement = '']) |
Parameters:
EXAMPLE
Here is simple example of Censored string.
Censored string in codeigniter example:-
// Views parts <?php $disallowed = array('darn', 'shucks', 'golly', 'phooey'); $string = word_censor($string, $disallowed, 'Beep!'); echo $string; ?> |
The output will be like this –
6. highlighted code string
Syntax of highlighted code string function is
Syntax of highlighted code string function is:-
highlight_code($str) |
Parameters:
EXAMPLE
Here is simple example of highlighted code string.
Highlighted code string in codeigniter example:-
// Views parts <?php $string = "Wecome to solid coupon"; $string = highlight_code($string); echo $string; ?> |
The output will be like this –
7. Highlighted phase string
Syntax of highlighted phase string function is
Syntax of highlighted phase string function is:-
highlight_phrase($str, $phrase[$tag_open = '<mark>'[$tag_close = '</mark>']]) |
Parameters:
EXAMPLE
Here is simple example of highlighted phase string.
Highlighted phase string in codeigniter example:-
// Views parts <?php $string = "Welcome to Solid Coupon And TutorialsPlane."; echo highlight_phrase($string, "Solid Coupon", '<span style="color:#990000;">', '</span>'); ?> |
The output will be like this –
8. Word-wrapped string
Syntax of word-wrapped string function is
Syntax of word-wrapped string function is:-
word_wrap($str[$charlim = 76]) |
Parameters:
EXAMPLE
Here is simple example of Word-wrapped string.
Word-wrapped string in codeigniter example:-
// Views parts <?php $string = "welcome to solid coupon."; echo word_wrap($string, 5); ?> |
The output will be like this –
9. Ellipsized string
Syntax of ellipsized string function is
Syntax of ellipsized string function is:-
ellipsize($str, $max_length[$position = 1[$ellipsis = '…']]) |
Parameters:
EXAMPLE
Here is simple example of Ellipsized string.
Ellipsized string in codeigniter example:-
// Views parts <?php $str = 'this_string_is_entirely_too_long_and_might_break_my_design.jpg'; echo ellipsize($str, 32, .5); ?> |
The output will be like this –
Advertisements