Highlight.php 789 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. if(!defined('APP_KEY')) { exit('Access Denied'); }
  3. class Helper_Highlight implements Suco_Helper_Interface
  4. {
  5. protected $_str;
  6. protected $_keyword;
  7. public static function callback($args)
  8. {
  9. return new self($args[0], $args[1]);
  10. }
  11. public function __construct($str, $keyword)
  12. {
  13. $this->_str = $str;
  14. $this->_keyword = $keyword;
  15. }
  16. public function __toString()
  17. {
  18. $str = $this->_str;
  19. if (!$str) {
  20. return '';
  21. }
  22. if (!empty($this->_keyword)) {
  23. $keywords = explode(" ", $this->_keyword);
  24. foreach ($keywords as $keyword) {
  25. $str = preg_replace('#('.$keyword.')#i', '<font color="red">$1</font>', $str);
  26. }
  27. }
  28. return $str;
  29. }
  30. }