PHP sets the red color for keywords in the text content. _ PHP Tutorial

Source: Internet
Author: User
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...

    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.