PHP redacts the keywords in the text content,_PHP Tutorial
PHP redacts the keywords in the text content, Sometimes when we display an article, we may need to redact certain keywords and highlight them , so that we can quickly find and locate these keywords, let’s take a look at the specific implementation code. /** * Keyword set red 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’,’keywords’, ‘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 Xiaojun’; $info_arr = array(‘photo_title’ => ‘womejiojd, we are all surrounded by anti-static low farts, Xiaojun’s chicken jelly, and the footbath is big’); $search_arr = array(‘Xiaojun’); $ret = set_arr_keyword_red($info_arr, $search_arr); dump($ret); Articles you may be interested in: When ThinkPHP makes text watermarks, it prompts to call an undefined function…