modifiercompiler.to_charset.php 788 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. /**
  3. * Smarty plugin
  4. *
  5. * @package Smarty
  6. * @subpackage PluginsModifierCompiler
  7. */
  8. /**
  9. * Smarty to_charset modifier plugin
  10. *
  11. * Type: modifier<br>
  12. * Name: to_charset<br>
  13. * Purpose: convert character encoding from internal encoding to $charset
  14. *
  15. * @author Rodney Rehm
  16. * @param array $params parameters
  17. * @return string with compiled code
  18. */
  19. function smarty_modifiercompiler_to_charset($params, $compiler)
  20. {
  21. if (!Smarty::$_MBSTRING) {
  22. // FIXME: (rodneyrehm) shouldn't this throw an error?
  23. return $params[0];
  24. }
  25. if (!isset($params[1])) {
  26. $params[1] = '"ISO-8859-1"';
  27. }
  28. return 'mb_convert_encoding(' . $params[0] . ', ' . $params[1] . ', "' . addslashes(Smarty::$_CHARSET) . '")';
  29. }
  30. ?>