| 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx

PHP怎么给文字内容中的关键字进行标红,高亮处理?

0
PHP HTML C/C++ 1953 次浏览

有些时候我们在显示一篇文章的时候,可能需要把某些关键字进行标红,高亮显示,以便我们能快速的查找和定位这些关键字,下面让我们看看具体实现的代码。
 

有些时候我们在显示一篇文章的时候,可能需要把某些关键字进行标红,高亮显示,以便我们能快速的查找和定位这些关键字,下面让我们看看具体实现的代码。

/**
  * 关键字套红方法
  * 
  * @access public
  * @param array $options 参数数组
  *  <li> $info_arr  array  内容</li>
  *  <li> $search_arr array  关键词数组 </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_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", "<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小君';
$info_arr = array('photo_title' => 'womejiojd我们都围殴防静低屁啊小君鸡冻啊泡脚盆大');
$search_arr = array('小君');
$ret = set_arr_keyword_red($info_arr, $search_arr);
dump($ret );


问答来自:php中文网 http://www.php.cn/wenda/3283.html

2个答案

0

Jokerslot191 heavy giveaway slot, Santa's Village Christmas season has arrived.

If you are looking for a slot game on the site Joker Slot is right for you. You're on the right track Because we are going to review another online slot game that is the most popular and has advantages such as low investment, high profit, easy money, standard, what games are there and how to play, please come and watch. Ok You will definitely be addicted to the fun of this game Joker191

Joker Slot191 has a lot more games than any other site. Must try.

Santa's Village Slot Game is another game on the Joker Slot website that we would recommend everyone to come and play. Especially people who like to play slot games This game comes in the form of a fun festival. With Christmas Will take everyone to win a lot of prizes With reels measuring 5 by 3, there is a simple payout All you have to do is have 3 or more identical images no matter which line you are in. You can get all the prize money. In the picture of a gift box It replaces the Wild symbol which can be used in place of any image. If when it comes out You will have a huge advantage. Because it will make the image exactly Sort them more easily. In addition, the image that we need the most. That is a picture of Santa Claus itself. That will bring us into playing santa free games and free sledding games. To receive more prize money

Join the fun with the Santa's Village slot game on the Joker Slot site with a payout rate of up to 15,000 times for arranging 5 gift boxes and followed by Santa's carrying a gift bag. There is a maximum payout of 10,000 times and there is a chance that you will get up to 12 free spins as long as you have a picture of Santa's cross. You can get free spins immediately PGSLOT

If you are one of the members who likes Santa's Village slots game, you would like to give it a try. Looking for a reliable website Provide stable service Get high security You can apply to become a member. And use the service with our website Joker Slot 24 hours a day to enjoy แจกหนัก

We assure you that Joker Slot is sure to please everyone. We offer a wide range of services. Collection of many world-class online casino games such as Baccarat, Hi Lo, Roulette, Blackjack, Fantan, Pokdeng, with more than 400 standard slot games, so you can be sure that You will get unlimited fun for sure. Just apply for membership เครดิตฟรี

0

ขอบคุณ รีวิว PG SLOT เกมส์ยอดฮิตในปัจจุบัน สำหรับเทคนิคในการเขียนโปรแกรมดีๆ นะค่ะ ฉันคิดว่าจะสามารถแก้ไชโค๊ดของฉันผ่านคำแนะนำนี้ได้เลยอย่างถูกต้อง ฉันจะรอติดตามเทคนิคต่อไปของคุณอีก หวังว่าคุณจะกลีบมาในเร็วๆ นี้นะค่ะ หรือคุณอยากมาแบ่งปันเทคนิคในการเขียนโปรแกรมของคุณกับฉันก็สามารถติดต่อฉันได้ตามบทความที่ฉันได้ฝากไว้ในนข้างต้น