PageRenderTime 48ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/Yab/Filter/Html.php

https://github.com/vib94/Framework
PHP | 49 lines | 23 code | 15 blank | 11 comment | 4 complexity | 9ee7cfa396e06c17e7a125e2c6b2c197 MD5 | raw file
  1. <?php
  2. /**
  3. * Yab Framework
  4. *
  5. * @category Yab_Filter
  6. * @package Yab_Filter_Html
  7. * @author Yann BELLUZZI
  8. * @copyright (c) 2010 YBellu
  9. * @license http://www.ybellu.com/yab-framework/license.html
  10. * @link http://www.ybellu.com/yab-framework
  11. */
  12. class Yab_Filter_Html extends Yab_Filter_Abstract {
  13. public function _filter($value) {
  14. mb_detect_order('ASCII, UTF-8, ISO-8859-15, ISO-8859-1, WINDOWS-1252, JIS, EUC-JP, SJIS');
  15. $encoding = mb_detect_encoding($value);
  16. if($encoding != 'UTF-8') {
  17. $value = strtr($value, array(
  18. chr(145) => "'",
  19. chr(146) => "'",
  20. chr(147) => '"',
  21. chr(148) => '"',
  22. chr(151) => '-',
  23. ));
  24. $value = mb_convert_encoding($value, 'UTF-8', $encoding ? $encoding : 'auto');
  25. }
  26. if(!$value)
  27. return $value;
  28. $html = htmlentities($value, ENT_QUOTES, 'UTF-8');
  29. if($html)
  30. return $html;
  31. return htmlentities($value, ENT_QUOTES);
  32. }
  33. }
  34. // Do not clause PHP tags unless it is really necessary