×

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

CodeIgniter Language Class

Language Class The CodeIgniter’s language class contains the various functionality that is used to access the language-specific files and text line for the purposes of internationalization. This class provides you suitability to add or...

4 minutes read.

Migration Class CodeIgniter

The CodeIgniter framework provides the migration class that helps the web developers to create and handle databases in a structured and streamlined manner. The migration classes are very useful when more than...

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

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.

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 Date helper

A date helper file contains some predefined functions that work with date functions. Before using the date function in CodeIgniter, you have to load the date helper in the controller. For example: $this->load->helper(‘date’); Functions of...

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

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 Email Class

CodeIgniter provides an e-mail library that helps to send a message from one application to another. You can create and send text messages easily in CodeIgniter application even you can set email...

9 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 CAPTCHA Helper

A CAPTCHA (Complete Automated Public Turning test to tell Computer and Humans Apart) helper is a function that is used in web application to check whether the user is human or machine. It...

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 File Helper

The file helper function is used to perform various tasks with files such as accessing files, writing data to files, deleting files, and more. Loading the File Helper Before using the file helper, you must...

7 minutes read.

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

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 Tutorial

What is CodeIgniter? CodeIgniter is an open-source framework for developing a dynamic web application with the use of PHP. It uses the MVC framework to develop the project, which is much...

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

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.