PHP set broken processing of keywords in text content _php instance

Source: Internet
Author: User
Tags arrays

Sometimes when we display an article, we may need to set broken some keywords and highlight them so that we can quickly find and locate them, so let's take a look at the implementation code.

/** * Keyword Set Broken method * @access public * @param array $options parameter arrays * <li> $info _arr Array Contents </li>  * <li> $search _arr array keyword arrays </li> * @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_arra
     Y ($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", "<font color= ' red ' >{$search _str}</font>", $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 June ';
$info _arr = Array (' photo_title ' => ' Womejiojd we all surround the static low fart, small June chicken frozen, bubble footbath big ');
$search _arr = Array (' Xiao June ');
$ret = set_arr_keyword_red ($info _arr, $search _arr); Dump ($ret);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.