iso_8859_1.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. /**
  3. * decode/iso8859-1.php
  4. *
  5. * This file contains iso-8859-1 decoding function that is needed to read
  6. * iso-8859-1 encoded mails in non-iso-8859-1 locale.
  7. *
  8. * @copyright 2003-2025 The SquirrelMail Project Team
  9. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  10. * @version $Id$
  11. * @package squirrelmail
  12. * @subpackage decode
  13. */
  14. /**
  15. * Decode iso8859-1 string
  16. * @param string $string Encoded string
  17. * @return string $string Decoded string
  18. */
  19. function charset_decode_iso_8859_1 ($string) {
  20. // don't do decoding when there are no 8bit symbols
  21. if (! sq_is8bit($string,'iso-8859-1'))
  22. return $string;
  23. $string = preg_replace_callback("/([\201-\237])/",
  24. (check_php_version(5, 3, 0)
  25. ? function($matches) { return '&#' . ord($matches[1]) . ';'; }
  26. : create_function ('$matches', 'return \'&#\' . ord($matches[1]) . \';\';')
  27. ),
  28. $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_callback("/([\241-\377])/",
  32. (check_php_version(5, 3, 0)
  33. ? function($matches) { return '&#' . ord($matches[1]) . ';'; }
  34. : create_function ('$matches', 'return \'&#\' . ord($matches[1]) . \';\';')
  35. ),
  36. $string);
  37. return $string;
  38. }