Home > Backend Development > PHP Tutorial > php正则加亮关键字函数方法

php正则加亮关键字函数方法

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-20 13:00:37
Original
1042 people have browsed it

php正则加亮关键字函数方法
正则加亮关键字

function highlight_words($str, $words, $color = '#FFFF00') { 
if(is_array($words)) { 
   foreach($words as $k => $word) { 
     $pattern[$k] = "/\b($word)\b/is"; 
     $replace[$k] = '<font style="background-color:'.$color.';">\\1</font>'; 
   } 
} 
else { 
   $pattern = "/\b($words)\b/is"; 
   $replace = '<font style="background-color:'.$color.';">\\1</font>'; 
} 
  
return preg_replace($pattern,$replace,$str); 
}  
Copy after login

 


Related labels:
php
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template