menu

Codeigniter Text Helper


Codeigniter Text Helper – Codeigniter Text Helper contains functions it will help us 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:

Functions:-

There are many functions are 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

    1. Word-limited string

    Syntax of Word-limited string function is

    Syntax of Word-limited string function is:-

      Parameters:

    • $str (string) : Input string
    • $limit (int) : Limit
    • $end_char (string) : End character (usually an ellipsis)
    • Returns : Word-limited string
    • Return type : string

    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:-

    The output will be like this –

    2. Character-limited string

    Syntax of Character-limited string function is

    Syntax of Character-limited string function is:-

      Parameters:

    • $str (string) : Input string
    • $n (int) : Number of characters
    • $end_char (string) : End character (usually an ellipsis)
    • Returns : Character-limited string
    • Return type : string

    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:-

    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:-

      Parameters:

    • $str (string) : Input string
    • Returns : A string with ASCII values converted to entities
    • Return type : string

    EXAMPLE

    Here is simple example of ASCII values converted to entities.

    ASCII values converted to entities in Codeigniter Example:-

    The output will be like this –

    4. accented characters converted

    Syntax of accented characters converted function is

    Syntax of accented characters converted function is:-

      Parameters:

    • $str (string) : Input string
    • Returns : A string with accented characters converted
    • Return type : string

    EXAMPLE

    Here is simple example of accented characters converted.

    accented characters converted in Codeigniter Example:-

    The output will be like this –

    5. Censored string

    Syntax of Censored string function is

    Syntax of Censored string function is:-

      Parameters:

    • $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

    EXAMPLE

    Here is simple example of Censored string.

    Censored string in Codeigniter Example:-

    The output will be like this –

    6. highlighted code string

    Syntax of highlighted code string function is

    Syntax of highlighted code string function is:-

      Parameters:

    • $str (string) : Input string
    • Returns : String with code highlighted via HTML
    • Return type : string

    EXAMPLE

    Here is simple example of highlighted code string.

    highlighted code string in Codeigniter Example:-

    The output will be like this –

    7. highlighted phase string

    Syntax of highlighted phase string function is

    Syntax of highlighted phase string function is:-

      Parameters:

    • $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

    EXAMPLE

    Here is simple example of highlighted phase string.

    highlighted phase string in Codeigniter Example:-

    The output will be like this –

    8. Word-wrapped string

    Syntax of Word-wrapped string function is

    Syntax of Word-wrapped string function is:-

      Parameters:

    • $str (string) : Input string
    • $charlim (int) : Character limit
    • Returns : Word-wrapped string
    • Return type : string

    EXAMPLE

    Here is simple example of Word-wrapped string.

    Word-wrapped string in Codeigniter Example:-

    The output will be like this –

    9. Ellipsized string

    Syntax of Ellipsized string function is

    Syntax of Ellipsized string function is:-

      Parameters:

    • $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

    EXAMPLE

    Here is simple example of Ellipsized string.

    Ellipsized string in Codeigniter Example:-

    The output will be like this –