PHP processes the keywords in the text content in red ,. PHP sets the red color for keywords in the text content. sometimes, when we display an article, some keywords may need to be set to red and highlighted, so that we can use PHP to set the red color for keywords in the text content,
Sometimes, when we display an article, some keywords may need to be highlighted in red so that we can quickly find and locate these keywords, next let's look at the specific implementation code.
/*** Red-keyword setting method ** @ access public * @ param array $ options parameter array *
$ Info_arr array content*
$ Search_arr array keyword array* @ Return int or array */function set_arr_keyword_red ($ info_arr, $ search_arr) {foreach ($ search_arr as $ search_str) {foreach ($ info_arr as $ key => $ info) {if (in_array ($ key, array ('item _ title', 'keyword', 'Photo _ title', 'Photo _ site', 'content ',))) {$ info = strip_tags ($ info); $ info = str_replace ('','', $ info); $ q_str_pos = stripos ($ info, $ search_str ); if (false! ==$ Q_str_pos) {$ info = csubstr ($ info, $ q_str_pos + 150); $ temp = csubstr ($ info, $ q_str_pos-150); $ info = substr ($ info, strlen ($ temp), 300); $ info = preg_replace ("/{$ search_str}/I", "{$ search_str}", $ info ); if ($ info_arr ['match _ key'] = '') $ info_arr ['match _ key'] = $ key;} else {$ info = csubstr ($ info, 300) ;}}$ info_arr [$ key] = $ info ;}return $ info_arr ;}$ str = 'woloveu '; $ info_arr = array ('photo _ title' => 'womejiojd, we all fight against static and low fart, Xiaojun chicken frozen, soaking basin big '); $ search_arr = array ('xiaojun '); $ ret = set_arr_keyword_red ($ info_arr, $ search_arr); dump ($ ret );
Articles you may be interested in:
- Call an undefined function exif_imagetype () when ThinkPHP is used as text watermark
- Example of creating an image and drawing text in PHP
- Php supports Chinese character string splitting functions
- PHP filters out non-Chinese characters and retains only Chinese characters
- Add text watermarks to images using php
- Php automatically identifies the Text Encoding and converts it to the target encoding method
- Php object-oriented and process-oriented methods to add text watermarks to images
- Php adds a text watermark to an image.
- Php image text watermark implementation code
- Compile a PHP program to check the number of Chinese characters in the string for instance sharing
When we display an article, some keywords may need to be highlighted to make it faster...