fsf changes, meant to be rebased on upstream
[squirrelmail.git] / functions / decode / iso_8859_1.php
CommitLineData
d672fcab 1<?php
4b4abf93 2
d6c32258 3/**
d672fcab 4 * decode/iso8859-1.php
d672fcab 5 *
d672fcab 6 * This file contains iso-8859-1 decoding function that is needed to read
7 * iso-8859-1 encoded mails in non-iso-8859-1 locale.
31841a9e 8 *
c997cbe6 9 * @copyright 2003-2021 The SquirrelMail Project Team
4b4abf93 10 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
31841a9e 11 * @version $Id$
d6c32258 12 * @package squirrelmail
13 * @subpackage decode
14 */
15
16/**
17 * Decode iso8859-1 string
18 * @param string $string Encoded string
19 * @return string $string Decoded string
d672fcab 20 */
df8c4d6d 21function charset_decode_iso_8859_1 ($string) {
e53c9681 22 // don't do decoding when there are no 8bit symbols
23 if (! sq_is8bit($string,'iso-8859-1'))
d672fcab 24 return $string;
25
6c4e2e9b 26 $string = preg_replace_callback("/([\201-\237])/",
9cfb0b2e 27 (check_php_version(5, 3, 0)
28 ? function($matches) { return '&#' . ord($matches[1]) . ';'; }
29 : create_function ('$matches', 'return \'&#\' . ord($matches[1]) . \';\';')
30 ),
31 $string);
d672fcab 32
33 /* I don't want to use 0xA0 (\240) in any ranges. RH73 may dislike it */
34 $string = str_replace("\240", '&#160;', $string);
35
6c4e2e9b 36 $string = preg_replace_callback("/([\241-\377])/",
9cfb0b2e 37 (check_php_version(5, 3, 0)
38 ? function($matches) { return '&#' . ord($matches[1]) . ';'; }
39 : create_function ('$matches', 'return \'&#\' . ord($matches[1]) . \';\';')
40 ),
41 $string);
d672fcab 42 return $string;
43}