source-class-Com.Tecnick.Unicode.Convert

It appears that you are using AdBlocking software. The cost of running this website is covered by advertisements. If you like it please feel free to a small amount of money to secure the future of this website.
  1: <?php
  2: /**
  3:  * Convert.php
  4:  *
  5:  * @since       2011-05-23
  6:  * @category    Library
  7:  * @package     Unicode
  8:  * @author      Nicola Asuni <info@tecnick.com>
  9:  * @copyright   2011-2015 Nicola Asuni - Tecnick.com LTD
 10:  * @license     http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
 11:  * @link        https://github.com/tecnickcom/tc-lib-unicode
 12:  *
 13:  * This file is part of tc-lib-unicode software library.
 14:  */
 15: 
 16: namespace Com\Tecnick\Unicode;
 17: 
 18: use \Com\Tecnick\Unicode\Data\Latin as Latin;
 19: 
 20: /**
 21:  * Com\Tecnick\Unicode\Convert
 22:  *
 23:  * @since       2015-07-13
 24:  * @category    Library
 25:  * @package     Unicode
 26:  * @author      Nicola Asuni <info@tecnick.com>
 27:  * @copyright   2011-2015 Nicola Asuni - Tecnick.com LTD
 28:  * @license     http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
 29:  * @link        https://github.com/tecnickcom/tc-lib-unicode
 30:  */
 31: class Convert extends \Com\Tecnick\Unicode\Convert\Encoding
 32: {
 33:     /**
 34:      * Returns the unicode string containing the character specified by value
 35:      *
 36:      * @param int $ord Unicode character value to convert
 37:      *
 38:      * @return string Returns the unicode string
 39:      */
 40:     public function chr($ord)
 41:     {
 42:         return mb_convert_encoding(pack('N', $ord), 'UTF-8', 'UCS-4BE');
 43:     }
 44: 
 45:     /**
 46:      * Returns the unicode value of the specified character
 47:      *
 48:      * @param string $chr Unicode character
 49:      *
 50:      * @return string Returns the unicode value
 51:      */
 52:     public function ord($chr)
 53:     {
 54:         list(, $uni) = unpack('N', mb_convert_encoding($chr, 'UCS-4BE', 'UTF-8'));
 55:         return $uni;
 56:     }
 57: 
 58:     /**
 59:      * Converts an UTF-8 string to an array of UTF-8 codepoints (integer values)
 60:      *
 61:      * @param string $str String to convert
 62:      *
 63:      * @return array
 64:      */
 65:     public function strToChrArr($str)
 66:     {
 67:         return preg_split('//u', $str, -1, PREG_SPLIT_NO_EMPTY);
 68:     }
 69: 
 70:     /**
 71:      * Converts an array of UTF-8 chars to an array of codepoints (integer values)
 72:      *
 73:      * @param array $chars Array of UTF-8 chars
 74:      *
 75:      * @return array
 76:      */
 77:     public function chrArrToOrdArr(array $chars)
 78:     {
 79:         return array_map(array($this, 'ord'), $chars);
 80:     }
 81: 
 82:     /**
 83:      * Converts an array of UTF-8 code points array of chars
 84:      *
 85:      * @param array $ords Array of UTF-8 code points
 86:      *
 87:      * @return array
 88:      */
 89:     public function ordArrToChrArr(array $ords)
 90:     {
 91:         return array_map(array($this, 'chr'), $ords);
 92:     }
 93: 
 94:     /**
 95:      * Converts an UTF-8 string to an array of UTF-8 codepoints (integer values)
 96:      *
 97:      * @param string $str Convert to convert
 98:      *
 99:      * @return array
100:      */
101:     public function strToOrdArr($str)
102:     {
103:         return $this->chrArrToOrdArr($this->strToChrArr($str));
104:     }
105: 
106:     /**
107:      * Extract a slice of the $uniarr array and return it as string
108:      *
109:      * @param array $uniarr  The input array of characters
110:      * @param int   $start   The position of the starting element
111:      * @param int   $end     The position of the first element that will not be returned.
112:      *
113:      * @return string
114:      */
115:     public function getSubUniArrStr(array $uniarr, $start = 0, $end = null)
116:     {
117:         if ($end === null) {
118:             $end = count($uniarr);
119:         }
120:         return implode(array_slice($uniarr, $start, ($end - $start)));
121:     }
122: }
123: 
 

© 2004-2017 – Nicola Asuni - Tecnick.com - All rights reserved.
about - disclaimer - privacy