using sq_is8bit function instead of ereg. Code reuse and fixes some problems
[squirrelmail.git] / functions / decode / iso_8859_1.php
CommitLineData
d672fcab 1<?php
d6c32258 2/**
d672fcab 3 * decode/iso8859-1.php
d672fcab 4 *
82d304a0 5 * Copyright (c) 2003-2004 The SquirrelMail Project Team
d672fcab 6 * Licensed under the GNU GPL. For full terms see the file COPYING.
7 *
8 * This file contains iso-8859-1 decoding function that is needed to read
9 * iso-8859-1 encoded mails in non-iso-8859-1 locale.
31841a9e 10 *
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) {
d672fcab 22 global $default_charset;
23
24 if (strtolower($default_charset) == 'iso-8859-1')
25 return $string;
26
e53c9681 27 // don't do decoding when there are no 8bit symbols
28 if (! sq_is8bit($string,'iso-8859-1'))
d672fcab 29 return $string;
30
31 $string = preg_replace("/([\201-\237])/e","'&#' . ord('\\1') . ';'",$string);
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
36 $string = preg_replace("/([\241-\377])/e","'&#' . ord('\\1') . ';'",$string);
37 return $string;
38}
39
e53c9681 40?>