PHP text processing in Red

Source: Internet
Author: User
The PHP text is highlighted in red to search for a keyword in the information content. the font color of the keyword is red.

/*** 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 );

    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.