iso8859-1.php 965 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. /*
  3. * decode/iso8859-1.php
  4. * $Id$
  5. *
  6. * Copyright (c) 2003 The SquirrelMail Project Team
  7. * Licensed under the GNU GPL. For full terms see the file COPYING.
  8. *
  9. * This file contains iso-8859-1 decoding function that is needed to read
  10. * iso-8859-1 encoded mails in non-iso-8859-1 locale.
  11. *
  12. */
  13. function charset_decode_iso8859_1 ($string) {
  14. global $default_charset;
  15. if (strtolower($default_charset) == 'iso-8859-1')
  16. return $string;
  17. /* Only do the slow convert if there are 8-bit characters */
  18. /* there is no 0x80-0x9F letters in ISO8859-* */
  19. if ( ! ereg("[\241-\377]", $string) )
  20. return $string;
  21. $string = preg_replace("/([\201-\237])/e","'&#' . ord('\\1') . ';'",$string);
  22. /* I don't want to use 0xA0 (\240) in any ranges. RH73 may dislike it */
  23. $string = str_replace("\240", '&#160;', $string);
  24. $string = preg_replace("/([\241-\377])/e","'&#' . ord('\\1') . ';'",$string);
  25. return $string;
  26. }
  27. ?>