iso_8859_1.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. /**
  3. * decode/iso8859-1.php
  4. *
  5. * Copyright (c) 2003-2004 The SquirrelMail Project Team
  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.
  10. *
  11. * @version $Id$
  12. * @package squirrelmail
  13. * @subpackage decode
  14. */
  15. /**
  16. * Decode iso8859-1 string
  17. * @param string $string Encoded string
  18. * @return string $string Decoded string
  19. */
  20. function charset_decode_iso_8859_1 ($string) {
  21. global $default_charset;
  22. if (strtolower($default_charset) == 'iso-8859-1')
  23. return $string;
  24. /* Only do the slow convert if there are 8-bit characters */
  25. /* there is no 0x80-0x9F letters in ISO8859-* */
  26. if ( ! ereg("[\241-\377]", $string) )
  27. return $string;
  28. $string = preg_replace("/([\201-\237])/e","'&#' . ord('\\1') . ';'",$string);
  29. /* I don't want to use 0xA0 (\240) in any ranges. RH73 may dislike it */
  30. $string = str_replace("\240", '&#160;', $string);
  31. $string = preg_replace("/([\241-\377])/e","'&#' . ord('\\1') . ';'",$string);
  32. return $string;
  33. }
  34. ?>