PageRenderTime 54ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/libs/Smarty-2.6.26/plugins/modifier.strip_tags.php

http://sifo.googlecode.com/
PHP | 68 lines | 34 code | 7 blank | 27 comment | 10 complexity | 686a8b1175b225f5d1e0f4b2bdb8efab MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0, BSD-3-Clause
  1. <?php
  2. /**
  3. * Smarty plugin
  4. * @package Smarty
  5. * @subpackage plugins
  6. */
  7. /**
  8. * Smarty strip_tags modifier plugin
  9. *
  10. * Type: modifier
  11. * Name: strip_tags
  12. * Purpose: strip html tags from text
  13. * @link http://www.smarty.net/manual/en/language.modifier.strip.tags.php
  14. * strip_tags (Smarty online manual)
  15. *
  16. * @author Monte Ohrt <monte at="" ohrt="" dot="" com="">
  17. * @author Jordon Mears <jordoncm at="" gmail="" dot="" com="">
  18. *
  19. * @version 2.0
  20. *
  21. * @param string
  22. * @param boolean optional
  23. * @param string optional
  24. * @return string
  25. */
  26. function smarty_modifier_strip_tags($string) {
  27. switch(func_num_args()) {
  28. case 1:
  29. $replace_with_space = true;
  30. break;
  31. case 2:
  32. $arg = func_get_arg(1);
  33. if($arg === 1 || $arg === true || $arg === '1' || $arg === 'true') {
  34. // for full legacy support || $arg === 'false' should be included
  35. $replace_with_space = true;
  36. $allowable_tags = '';
  37. } elseif($arg === 0 || $arg === false || $arg === '0' || $arg === 'false') {
  38. // for full legacy support || $arg === 'false' should be removed
  39. $replace_with_space = false;
  40. $allowable_tags = '';
  41. } else {
  42. $replace_with_space = true;
  43. $allowable_tags = $arg;
  44. }
  45. break;
  46. case 3:
  47. $replace_with_space = func_get_arg(1);
  48. $allowable_tags = func_get_arg(2);
  49. break;
  50. }
  51. if($replace_with_space) {
  52. $string = preg_replace('!(<[^>]*?>)!', '$1 ', $string);
  53. }
  54. $string = strip_tags($string, $allowable_tags);
  55. if($replace_with_space) {
  56. $string = preg_replace('!(<[^>]*?>) !', '$1', $string);
  57. }
  58. return $string;
  59. }
  60. /* vim: set expandtab: */
  61. ?>