Tutorialsplane

Codeigniter Typography Class Library


Codeigniter Typography Class Library -We can load typography class library like this $this->load->library(‘typography’);. This library provide various functions that are used to adjust formating in text. Here in this tutorial, we are going to explain how to use typography class library.


Codeigniter typography class library | Example

Let us understand how typography class library works in codeigniter with examples.

Load typography class library

First load typography class library to use its functions, this library can be loaded simply as below-

How to load typography class library:

$this->load->library('typography');

Class reference:-

There are following references available in typography class library. Now we will explain.

1. Protect braced quotes.

This reference is used to desirable to protect single and double quotes within curly braces.

$protect_braced_quotes = FALSE
Example.

<?php defined('BASEPATH') OR exit('No direct script access allowed');
class typography_controller extends CI_Controller 
{
public function protectbraces()
{
$this-?>load->library('typography');	
echo $this->typography->protect_braced_quotes=true;		
}
}
?>

2. Auto typography.

This function is used to format text so that it is semantically and typographically correct HTML.

auto_typography($str[, $reduce_linebreaks = FALSE])
Example.
<?php defined('BASEPATH') OR exit('No direct script access allowed');
class typography_controller extends CI_Controller 
{
public function autotypography()
{
$this-?>load->library('typography');
$string = "This is my first paragraph!";
$string = $this->typography->auto_typography($string);
echo $string;	
}
}
?>

Output will be like this:-

3. Format characters.

This function is similar to auto typography. except that it only does character conversion

format_characters($str)
Example.
<?php defined('BASEPATH') OR exit('No direct script access allowed');
class typography_controller extends CI_Controller 
{
public function character()
{
$this-?>load->library('typography');
$string = "Solid coupon!";
$string = $this->typography->format_characters($string);
echo $string;	
}
}
?>

Output will be like this:-

4. nl2br except pre.

This function is is used to converts newlines to breakline tags unless they appear within pre tags

nl2br_except_pre($str)
Example.
<?php defined('BASEPATH') OR exit('No direct script access allowed');
class typography_controller extends CI_Controller 
{
public function breakline()
{
$this-?>load->library('typography');
$string = "Welcome to \n tutorialsplane!";
$string = $this->typography->nl2br_except_pre($string);
echo $string;	
}
}
?>

Output will be like this:-

Models

Connect Database

Helpers

Libraries

Helper Reference

Library Reference

Database Reference