×

CodeIgniter Number helper

The number helper file contains some predefined function that deals with numeric data to display numbers in bytes format.

Load a Number Helper

You must load a number helper file in the controller to perform a number function in the CodeIgniter application.

Syntax

$this->load->helper (‘number’);

Function of Number Helper:

  1. byte_format(): As the name suggests, it is used to convert a large number into Bytes, KB, MB, GB and TB format.

Syntax

byte_format ( $num [, $precision = 1 ]);
  • $num: It defines the number of bytes passed in the byte_format () function.
  • $precision: It defines the number of floating points can be precise in byte_format ().

Create a simple program of Number helper

Create a controller file Online.php and save it in application/controller folder. After that, write the following program in your controller file.

Online.php

<?php class Online extends CI_Controller
 {
     public function hello_function() {
     $this->load->helper('number');
 echo "Size in Bytes :".byte_format(576)."<br>"; 
 echo "Size in KB :".byte_format(7865)."<br>"; 
 echo "Size in KB :".byte_format(78658)."<br>";  
 echo "Size in MB :".byte_format(1472486)."<br>"; 
 echo "Size in GB :".byte_format(76589402356)."<br>"; 
 echo "Size in TB :".byte_format(1234567891234);
 }
 } 
 ?> 

When you execute the above program in localhost by invoking the URL localhost/CodeIgniter-3.1.11/index.php/Online, it shows the output, as shown below.

CodeIgniter Number helper

Path Helper

The path helper file has some predefined functions that allow you to access the file path on the server.

$this->load->helper (‘path’);

Function of the Path helper

1.Set_realpath (): This function is used to set and access the file or directory path on the server without create of symbolic links. And if the file path is not existing, it shows an error message on the server.

Syntax

set_realpath ( $path, $check_existance = FALSE ] );
  • $path : It takes the path of a particular file or folder as a string that can access on the server.
  • $check_existance : If you want to show an error message on the server when a particular file or directory is not valid, you can use a Boolean value such as true or false.

Example:

Create a controller file Online.php and save it in application/controller/Online.php. After that, write the following program in your controller file.

Online.php

<?php
 class Online extends CI_Controller
 { 
 public function set_path()  // It is the set_path method
 {   
 echo "<title> Tutorial and Example </title>";
     $this->load->helper('path'); // load path helper
     echo "SET REAL PATH :";
     $file_path = '/www/CodeIgniter-3.1.11/system/language/english';
 echo set_realpath($file_path); 
 echo "<br>";   
  $non_existent_file = '/application/to/non-defined-file_path.txt';
 echo set_realpath($non_existent_file, TRUE);  /* here TRUE is used for showing an error message on the server */
 }
 }
 ?> 

When you execute the above program in localhost by invoking the URL localhost/CodeIgniter-3.1.11/index.php/Online, it shows the output, as shown below.

CodeIgniter Number helper

Related Topics

Retrieve data from Database

Retrieve data from the Database Now we will discuss how we can retrieve data from the database that we have inserted to the employees table of the database in our previous topic “inserted...

2 minutes read.

CodeIgniter Calendaring Library

The calendar library contains various functions that are used to create a dynamic calendar. It also enables you to pass the data to calendar cells and 100% control over the calendar design. Load...

7 minutes read.

CodeIgniter Benchmarking Class

The CodeIgniter contains the Benchmarking class that is used to calculate the time difference between two points or the memory usage of the passed statements in the application. By default, the Benchmarking...

7 minutes read.

CodeIgniter Pagination Class

Pagination Class The CodeIgniter framework provides a pagination class that is used in the data list to create pagination links in a web application. Generally, it is used to retrieve data records from...

10 minutes read.

Download Helper Codeigniter

Download Helper Codeigniter: The download helper function is used to download data from the server to your computer. The data can be any format like text, jpg, mp3, mp4, etc. Loading...

2 minutes read.

How to remove an index.php file from the Codeigniter URLs?

As we know, a URL in CodeIgniter is designed in such a way that it would be search engine and human friendly, too, rather than using a standard approach to create a...

2 minutes read.

Calendaring Class CodeIgniter

Calendaring Class The calendar library contains various functions that are used to create a dynamic calendar. It also enables you to pass the data to calendar cells and 100% control over the calendar...

6 minutes read.

CodeIgniter ZIP Encoding Class

ZIP Encoding Class The CodeIgniter provides a Zip encoding class that are used to compress a large file into a Zip archives. And this archives files can be downloaded either to your desktop or...

5 minutes read.

CodeIgniter Inflector Helper

The inflector helper file contains some predefined function that allows users to change their English words into plural, singular, and camel case, etc. Loading an Inflector Helper Before using an inflector helper function, you must...

3 minutes read.

CodeIgniter Security Class

Security Class The security class provides various function that helps to create a secure application and process input data securely to the application. This class is preloaded in the CodeIgniter application, so you...

4 minutes read.

Image Manipulation Codeigniter

Image Manipulation A Codeigniter provides an image manipulation class that is used for resizing, cropping, rotation, and many other manipulation tasks. This class also support three major image libraries such as GD/GD2, NetPBM, and...

11 minutes read.

CodeIgniter Smiley Helper

The smiley helper file contains smiley images that are used in the application for showing emotions and comments while chatting with others. Load a Smiley Helper Before using Smiley Helper in the CodeIgniter application, you...

4 minutes read.

CodeIgniter Form Helper

A form helper file contains different functions that works with forms. It is used to create various functionality in a form such as dropdown, radio button, password, upload, hidden data, etc. These functionalities...

12 minutes read.

CodeIgniter HTML Helper

The HTML helper function is used in CodeIgniter to provide various functionality, such as headings, images, links, list tags, etc. Loading the HTML Helper Before using the html helper function, you must load the...

7 minutes read.

CodeIgniter Views

A View is a presentational part which shows the information to the users. It is a complex web page which contains navbar, header, footer, sidebar, etc. A view file cannot be called directly...

5 minutes read.

CodeIgniter Output class

Output class The CodeIgniter framework contains a core class that is an Output class. It  includes the various functions that are used to send the final web page to the requesting browser. In...

8 minutes read.

CodeIgniter Text Helper

The text helper contains the various function that is used to operate with text such as define a word limit and characters limit, conversion of word from ASCII to entities, etc. Loading the text...

4 minutes read.

CodeIgniter Routes

The Routes are used to handle URL requests on the browser. It matches the URL request to the predefined routes in CodeIgniter. Therefore, a file must be predefined as a routes.php file to...

6 minutes read.

CodeIgniter Creating Library

As we know, CodeIgniter has a large collection of library functions that are stored in the system/libraries folder. CodeIgniter also provides some additional functionality in library files. For example, if you want to...

3 minutes read.

CodeIgniter Controller

As its name suggest that it is a Controller that controls the web application, and it works as an intermediary between the Models and the View. A controller takes requests from the user...

3 minutes read.