You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

modifier.needle.php 1.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /**
  3. * Smarty shared plugin
  4. * @package Smarty
  5. * @subpackage plugins
  6. */
  7. /**
  8. * Function: smarty_needle
  9. * Purpose: Used to find a string in a string
  10. * Options: enter "case" to make case senstative
  11. * Example: needle( 'Gabe-was-here', 'here' ) returns true
  12. * Example2: needle( 'Gabe was here', 'gabe' ) returns true
  13. * Example: needle ('Gabe was there', 'sde') returns false
  14. * Smarty Sample: {$haystack|needle:"string"}
  15. * Smarty Sample: {$haystack|needle:"string":"case"}
  16. * @author Gabe LeBlanc "raven"
  17. * @param string
  18. * @return boolean
  19. */
  20. function smarty_modifier_needle($haystack, $needle, $cases = "nocase") {
  21. if(!empty($haystack) ) {
  22. if($cases == "nocase") {
  23. if(stristr($haystack, $needle)) {
  24. return true;
  25. }else{
  26. return false;
  27. }
  28. }elseif($cases == "case") {
  29. if(strstr($haystack, $needle)) {
  30. return true;
  31. }else{
  32. return false;
  33. }
  34. }
  35. }else{
  36. return false;
  37. }
  38. }
  39. ?>