Source for file cp1256.php

Documentation is available at cp1256.php

  1. <?php
  2.  
  3. /**
  4.  * cp1256 encoding functions
  5.  *
  6.  * takes a string of unicode entities and converts it to a cp1256 encoded string
  7.  * Unsupported characters are replaced with ?.
  8.  *
  9.  * @copyright 2004-2020 The SquirrelMail Project Team
  10.  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  11.  * @version $Id: cp1256.php 14845 2020-01-07 08:09:34Z pdontthink $
  12.  * @package squirrelmail
  13.  * @subpackage encode
  14.  */
  15.  
  16. /**
  17.  * Converts string to cp1256
  18.  * @param string $string text with numeric unicode entities
  19.  * @return string cp1256 encoded text
  20.  */
  21. function charset_encode_cp1256 ($string{
  22.    // don't run encoding function, if there is no encoded characters
  23.    if (preg_match("'&#[0-9]+;'",$string) ) return $string;
  24.  
  25.     $string=preg_replace_callback("/&#([0-9]+);/",'unicodetocp1256',$string);
  26.  
  27.     return $string;
  28. }
  29.  
  30. /**
  31.  * Return cp1256 symbol when unicode character number is provided
  32.  *
  33.  * This function is used internally by charset_encode_cp1256
  34.  * function. It might be unavailable to other SquirrelMail functions.
  35.  * Don't use it or make sure, that functions/encode/cp1256.php is
  36.  * included.
  37.  *
  38.  * @param array $matches array with first element a decimal unicode value
  39.  * @return string cp1256 character
  40.  */
  41. function unicodetocp1256($matches{
  42.     $var $matches[1];
  43.  
  44.     $cp1256chars=array('160' => "\xA0",
  45.                        '162' => "\xA2",
  46.                        '163' => "\xA3",
  47.                        '164' => "\xA4",
  48.                        '165' => "\xA5",
  49.                        '166' => "\xA6",
  50.                        '167' => "\xA7",
  51.                        '168' => "\xA8",
  52.                        '169' => "\xA9",
  53.                        '171' => "\xAB",
  54.                        '172' => "\xAC",
  55.                        '173' => "\xAD",
  56.                        '174' => "\xAE",
  57.                        '175' => "\xAF",
  58.                        '176' => "\xB0",
  59.                        '177' => "\xB1",
  60.                        '178' => "\xB2",
  61.                        '179' => "\xB3",
  62.                        '180' => "\xB4",
  63.                        '181' => "\xB5",
  64.                        '182' => "\xB6",
  65.                        '183' => "\xB7",
  66.                        '184' => "\xB8",
  67.                        '185' => "\xB9",
  68.                        '187' => "\xBB",
  69.                        '188' => "\xBC",
  70.                        '189' => "\xBD",
  71.                        '190' => "\xBE",
  72.                        '215' => "\xD7",
  73.                        '224' => "\xE0",
  74.                        '226' => "\xE2",
  75.                        '231' => "\xE7",
  76.                        '232' => "\xE8",
  77.                        '233' => "\xE9",
  78.                        '234' => "\xEA",
  79.                        '235' => "\xEB",
  80.                        '238' => "\xEE",
  81.                        '239' => "\xEF",
  82.                        '244' => "\xF4",
  83.                        '247' => "\xF7",
  84.                        '249' => "\xF9",
  85.                        '251' => "\xFB",
  86.                        '252' => "\xFC",
  87.                        '338' => "\x8C",
  88.                        '339' => "\x9C",
  89.                        '402' => "\x83",
  90.                        '710' => "\x88",
  91.                        '1548' => "\xA1",
  92.                        '1563' => "\xBA",
  93.                        '1567' => "\xBF",
  94.                        '1569' => "\xC1",
  95.                        '1570' => "\xC2",
  96.                        '1571' => "\xC3",
  97.                        '1572' => "\xC4",
  98.                        '1573' => "\xC5",
  99.                        '1574' => "\xC6",
  100.                        '1575' => "\xC7",
  101.                        '1576' => "\xC8",
  102.                        '1577' => "\xC9",
  103.                        '1578' => "\xCA",
  104.                        '1579' => "\xCB",
  105.                        '1580' => "\xCC",
  106.                        '1581' => "\xCD",
  107.                        '1582' => "\xCE",
  108.                        '1583' => "\xCF",
  109.                        '1584' => "\xD0",
  110.                        '1585' => "\xD1",
  111.                        '1586' => "\xD2",
  112.                        '1587' => "\xD3",
  113.                        '1588' => "\xD4",
  114.                        '1589' => "\xD5",
  115.                        '1590' => "\xD6",
  116.                        '1591' => "\xD8",
  117.                        '1592' => "\xD9",
  118.                        '1593' => "\xDA",
  119.                        '1594' => "\xDB",
  120.                        '1600' => "\xDC",
  121.                        '1601' => "\xDD",
  122.                        '1602' => "\xDE",
  123.                        '1603' => "\xDF",
  124.                        '1604' => "\xE1",
  125.                        '1605' => "\xE3",
  126.                        '1606' => "\xE4",
  127.                        '1607' => "\xE5",
  128.                        '1608' => "\xE6",
  129.                        '1609' => "\xEC",
  130.                        '1610' => "\xED",
  131.                        '1611' => "\xF0",
  132.                        '1612' => "\xF1",
  133.                        '1613' => "\xF2",
  134.                        '1614' => "\xF3",
  135.                        '1615' => "\xF5",
  136.                        '1616' => "\xF6",
  137.                        '1617' => "\xF8",
  138.                        '1618' => "\xFA",
  139.                        '1657' => "\x8A",
  140.                        '1662' => "\x81",
  141.                        '1670' => "\x8D",
  142.                        '1672' => "\x8F",
  143.                        '1681' => "\x9A",
  144.                        '1688' => "\x8E",
  145.                        '1705' => "\x98",
  146.                        '1711' => "\x90",
  147.                        '1722' => "\x9F",
  148.                        '1726' => "\xAA",
  149.                        '1729' => "\xC0",
  150.                        '1746' => "\xFF",
  151.                        '8204' => "\x9D",
  152.                        '8205' => "\x9E",
  153.                        '8206' => "\xFD",
  154.                        '8207' => "\xFE",
  155.                        '8211' => "\x96",
  156.                        '8212' => "\x97",
  157.                        '8216' => "\x91",
  158.                        '8217' => "\x92",
  159.                        '8218' => "\x82",
  160.                        '8220' => "\x93",
  161.                        '8221' => "\x94",
  162.                        '8222' => "\x84",
  163.                        '8224' => "\x86",
  164.                        '8225' => "\x87",
  165.                        '8226' => "\x95",
  166.                        '8230' => "\x85",
  167.                        '8240' => "\x89",
  168.                        '8249' => "\x8B",
  169.                        '8250' => "\x9B",
  170.                        '8364' => "\x80",
  171.                        '8482' => "\x99");
  172.  
  173.     if (array_key_exists($var,$cp1256chars)) {
  174.         $ret=$cp1256chars[$var];
  175.     else {
  176.         $ret='?';
  177.     }
  178.     return $ret;
  179. }

Documentation generated on Mon, 13 Jan 2020 04:22:15 +0100 by phpDocumentor 1.4.3