removed local directory name used for testing.
[squirrelmail.git] / functions / encode / us_ascii.php
CommitLineData
3eb6bd05 1<?php
2/**
3 * us_ascii encoding functions
4 *
5 * takes a string of unicode entities and converts it to a us-ascii encoded string
6 * Unsupported characters are replaced with ?.
7 *
8 * @version $Id$
6c84ba1e 9 * @copyright Copyright &copy; 2004-2005 The SquirrelMail Project Team
3eb6bd05 10 * @package squirrelmail
11 * @subpackage encode
12 */
13
14/**
15 * Converts string to us-ascii
16 * @param string $string text with numeric unicode entities
17 * @return string us-ascii encoded text
18 */
19function charset_encode_us_ascii ($string) {
20 // don't run encoding function, if there is no encoded characters
21 if (! preg_match("'&#[0-9]+;'",$string) ) return $string;
22
23 $string=preg_replace("/&#([0-9]+);/e","unicodetousascii('\\1')",$string);
24 // $string=preg_replace("/&#[xX]([0-9A-F]+);/e","unicodetousascii(hexdec('\\1'))",$string);
91e0dccc 25
3eb6bd05 26 return $string;
27}
28
29/**
30 * Return us-ascii symbol when unicode character number is provided
91e0dccc 31 *
3eb6bd05 32 * This function is used internally by charset_encode_us_ascii
598294a7 33 * function. It might be unavailable to other SquirrelMail functions.
91e0dccc 34 * Don't use it or make sure, that functions/encode/us_ascii.php is
35 * included.
3eb6bd05 36 *
37 * @param int $var decimal unicode value
38 * @return string us-ascii character
39 */
40function unicodetousascii($var) {
41
42 if ($var < 128) {
43 $ret = chr ($var);
44 } else {
45 $ret='?';
46 }
47 return $ret;
48}
49?>