Skip to content
World Wide Web Server edited this page Jul 4, 2012 · 9 revisions

Category:Contributions::Plugins

The unicode2iso Plugin for CodeIgniter is a simple plugin that allow you to covert an UTF-8 string containing HTML into an ISO-8859-1 string using HTML special chars without stripping the HTML of the original string.

You have to set manually in $retrieve all HTML elements wich you allow to be retrieved.

[b]Plugin home :[/b] [url=http://www.kromack.com/codeigniter/plugin-unicode2iso-pour-codeigniter/]unicode2iso Plugin[/url]

[b]How to use :[/b]

[code] <?php

$this->load->plugin('unicode2iso');

echo unicode2iso($yourString);

?> [/code]

[b]Plugin's code :[/b]

[code] <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**

  • unicode2iso plugin for CodeIgniter applications

  • @author : Samuel Sanchez, http://www.kromack.com/, April 2009

  • @link :

  • @license : free */

    /**

    • Take an UTF8 string, and return an ISO-8859-1 string with all HTML special chars encoded exept those defined in the $retrieve array.

    • @param string $str

    • @return string */ function unicode2iso($str) {

      //Define HTML elements to retrive after conversion $retrieve = array('
      ', '
      ', '
      ', '', '', '', '', '', '');

      //HTML special chars conversion $str = htmlentities($str, ENT_QUOTES, 'UTF-8');

      //ISO-8859-1 conversion $str = utf8_decode($str);

      //Now, we resore our HTML elements foreach($retrieve as $row) { $str = str_replace(htmlentities($row, ENT_QUOTES), $row, $str); }

      return $str;
      }

?> [/code]

Clone this wiki locally