PHP set broken processing of keywords in text content, _php tutorial

Source: Internet
Author: User

PHP Set broken the keywords in the text content,


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

/** * Keyword Set Broken method * * @access public * @param array $options parameter arrays *
  • $info _arr Array Contents
  • *
  • $search _arr array of keyword arrays
  • * @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 '; $info _arr = Array (' photo_title ' = ' Womejiojd we all beat the static low fart ah little June chicken frozen Ah bubble footbath big '); $search _arr = Array (' little June '); $ ret = set_arr_keyword_red ($info _arr, $search _arr);d UMP ($ret);

    Articles you may be interested in:

      • thinkphp a undefined function exif_imagetype () solution when making a text watermark
      • Examples of creating images and drawing text in PHP
      • PHP support for Chinese string segmentation functions
      • PHP implementation filters out non-kanji characters to keep Chinese character only
      • PHP Add text watermark to image
      • PHP automatic recognition of text encoding and conversion to target encoding method
      • PHP Object-oriented and process-oriented two methods to add text watermark to a picture
      • PHP to add text to the image Watermark method Summary
      • PHP Image Add text watermark implementation code
      • To write an instance share of the number of Chinese characters in a PHP program check string

    http://www.bkjia.com/PHPjc/1119967.html www.bkjia.com true http://www.bkjia.com/PHPjc/1119967.html techarticle php to the text content in the keyword set broken processing, sometimes we display an article, we may need to put some keywords set broken, highlighting, so that we can quickly ...

  • 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.