Codeigniter Smiley Helper


Codeigniter Smiley Helper – Codeigniter smiley helper contains functions that help us to manage emoticons. $this->load->helper(‘smiley’); is used to load the helper. It has a renderer that takes plain text smileys, like 🙂 and turns them into a image representation, like smile!. Here in this tutorial we are going to explain how to use smiley helper in codeigniter.


Codeigniter smiley helper example

Let us first see how to load smiley helper in codeigniter and then use its function-

Load smiley helper

How to load smiley helper in codeingniter example:

 
$this->load->helper('smiley');

Functions:-

There are many functions are available in smiley helper. Now we will explain one by one with example.

    • 1. Clickable_smileys
    • 2. Smiley_js
    • 3. Parse_smileys

    1. Clickable_smileys

    Syntax of clickable_smileys function is

    Syntax of clickable_smileys function is:-

    get_clickable_smileys($image_url[$alias = ''[$smileys = NULL]])	
    

      Parameters:

    • $image_url (string) : URL path to the smileys directory
    • $alias (string) : Field alias
    • Returns : An array of ready to use smileys
    • Return type : array

    This function contain your smiley images wrapped in a clickable link.

    EXAMPLE

    Here is simple example of clickable_smileys.

    Clickable_smileys in codeigniter example:-

    //Controllers part
    public function securityCheck()
    	{
    		$this->load->helper('smiley');
    		$this->load->view('smiley_view');
    	}
    
    // Views parts
    
    <?php $str = 'Here are some smileys: :-)  ;-)';
    $smileyFolderPath = "http://localhost/Codeigniter/media/smileys/";
    $str = parse_smileys($str, $smileyFolderPath);
    echo $str;
    ?>
    

    Where $smileyFolderPath is the folder path that contains the smiley images.

    The output of the above example will be something like this –

    2. Smiley_js

    Syntax of smiley_js function is

    Syntax of smiley_js function is:-

    smiley_js([$alias = ''[$field_id = ''[$inline = TRUE]]])		
    

      Parameters:

    • $alias (string) : Field alias
    • $field_id (string) : Field ID
    • $inline (bool) : Whether we’re inserting an inline smiley
    • Returns : Smiley-enabling JavaScript code
    • Return type : String

    This function is designed to be placed into the area of your web page.

    EXAMPLE

    Here is simple example of smiley_js.

    Smiley_js in codeigniter example:-

    // Views parts
    
    <?php echo smiley_js(); ?>
    

    The output of the above example will be something like this –

    3. Parse_smileys

    Syntax of parse_smileys function is

    Syntax of parse_smileys function is:-

    parse_smileys([$str = ''[$image_url = ''[$smileys = NULL]]])		
    

      Parameters:

    • $str (string) : Text containing smiley codes
    • $image_url (string) : URL path to the smileys directory
    • $smileys (array) : An array of smileys
    • Returns : Parsed smileys
    • Return type : String

    In this function first parameter must contain your string, the second must contain the URL to your smiley folder.

    EXAMPLE

    Here is simple example of parse_smileys.

    Parse_smileys in codeigniter example:-

    // Views parts
    
    <?php $str = 'Welcome To TutorialsPlane: :-)  ;-)';
    $str = parse_smileys($str, 'http://localhost/Codeigniter/media/smileys/');
    echo $str;
    ?>
    

    The output of the above example will be something like this –


    Advertisements

    Add Comment

    📖 Read More