helper_text.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /** This file is part of KCFinder project
  3. *
  4. * @desc Text processing helper class
  5. * @package KCFinder
  6. * @version 3.12
  7. * @author Pavel Tzonkov <sunhater@sunhater.com>
  8. * @copyright 2010-2014 KCFinder Project
  9. * @license http://opensource.org/licenses/GPL-3.0 GPLv3
  10. * @license http://opensource.org/licenses/LGPL-3.0 LGPLv3
  11. * @link http://kcfinder.sunhater.com
  12. */
  13. namespace kcfinder;
  14. class text {
  15. /** Replace repeated white spaces to single space
  16. * @param string $string
  17. * @return string */
  18. static function clearWhitespaces($string) {
  19. return trim(preg_replace('/\s+/s', " ", $string));
  20. }
  21. /** Normalize the string for HTML attribute value
  22. * @param string $string
  23. * @return string */
  24. static function htmlValue($string) {
  25. return
  26. str_replace('"', "&quot;",
  27. str_replace("'", '&#39;',
  28. str_replace('<', '&lt;',
  29. str_replace('&', "&amp;",
  30. $string))));
  31. }
  32. /** Normalize the string for JavaScript string value
  33. * @param string $string
  34. * @return string */
  35. static function jsValue($string) {
  36. return
  37. preg_replace('/\r?\n/', "\\n",
  38. str_replace('"', "\\\"",
  39. str_replace("'", "\\'",
  40. str_replace("\\", "\\\\",
  41. $string))));
  42. }
  43. }
  44. ?>