PHP to the text content in the keyword set broken processing keywords to optimize the key words Taobao keyword peer key

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

    The above introduces PHP to the text content of the key word set broken processing, including the keyword, PHP content, I hope that the PHP tutorial interested in a friend helpful.

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