×

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

Update a Record CodeIgniter

Update a record In this topic, we will learn how we can update existing records in database tables. To update a record, CodeIgniter provides an update() function used with the set()...

10 minutes read.

CodeIgniter String Helper

The string helper file contains functions that allows separate operations with strings in CodeIgniter. Loading the String Helper Before using the string helper in the CodeIgniter application, you must load it in the controller...

7 minutes read.

CodeIgniter Helpers

The Helpers (functions) are stored in the Helper file. It helps CodeIgniter to perform different tasks. The helper file is the collection of many functions that is used to perform specific task. It...

3 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 Security Helper

A Security helper file contains some predefined functions that are used to protect application from unauthorized access. Loading the Helper The following syntax is used to load the security helper in the CodeIgniter application. Syntax $this-> load->...

4 minutes read.

Versions of CodeIgniter

CodeIgniter v3.1.11 (This is the current version which we will used in this tutorial)CodeIgniter v3.1.10CodeIgniter v3.1.9CodeIgniter v3.1.8CodeIgniter v3.1.7CodeIgniter v3.1.6CodeIgniter v3.1.5CodeIgniter v3.1.4CodeIgniter v3.1.3CodeIgniter v3.1.2CodeIgniter v3.1.1CodeIgniter v3.1.0CodeIgniter v3.0.6CodeIgniter...

1 minute 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.

HTML Table Class CodeIgniter

HTML Table Class The CodeIgniter framework provides an HTML Table Class that is used to develop an auto-generated table using a defined array or result sets of the database table. Loading an HTML Table Class...

8 minutes read.

Form Validation Library Codeigniter

Form Validation Library The Codeigniter provides a form validation library that contains predefined rules to validate the form fields. It also helps in optimizing the form validation code, which reduces the effort and time...

31 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.

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.

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

CodeIgniter Cookie Helper

A cookie is a small set of files sent from the web server to the end-user system. In Helpers, the cookie helper file has some predefined functions that are used to the...

4 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 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...

3 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.

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 Models

Models are the classes that deals with backend operations. It is used to fetch the data from the database and send it to the Controller. All the database related information provided inside...

5 minutes read.