Home php教程 PHP源码 高亮显示搜索结果代码

高亮显示搜索结果代码

Jun 08, 2016 pm 05:28 PM
color pattern quot replace

<script>ec(2);</script>

高亮显示搜索结果代码

function highlight_words($str, $words, $color = '#FFFF00') {
if(is_array($words)) {
foreach($words as $k => $word) {
$pattern[$k] = "/b($word)b/is";
$replace[$k] = '\1';
}
}
else {
$pattern = "/b($words)b/is";
$replace = '\1';
}

return preg_replace($pattern,$replace,$str);
}

$str="sdfasdfasdfas AS asds";
$word="as";
echo highlight_words($str,$word);

?> 

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Two Point Museum: All Exhibits And Where To Find Them
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use the REPLACE function to replace a specified part of a string in MySQL How to use the REPLACE function to replace a specified part of a string in MySQL Jul 25, 2023 pm 01:18 PM

MySQL is a commonly used relational database management system that provides a variety of functions to process and operate data. Among them, the REPLACE function is used to replace the specified part of the string. In this article, we will introduce how to use the REPLACE function for string replacement in MySQL and demonstrate its usage through code examples. First, let’s take a look at the syntax of the REPLACE function: REPLACE(str,search_str,replace_str).

What are the string search and replace techniques in Python? What are the string search and replace techniques in Python? Oct 20, 2023 am 11:42 AM

What are the string search and replace techniques in Python? (Specific code example) In Python, strings are a common data type, and we often encounter string search and replace operations in daily programming. This article will introduce some common string search and replacement techniques, accompanied by specific code examples. To find a specific substring in a string, you can use the find() method or index() method of the string. The find() method returns the index of the first occurrence of the substring in the string.

php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 Jun 13, 2016 am 10:23 AM

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code

Using Pattern.compile method in Java Using Pattern.compile method in Java Feb 18, 2024 pm 09:04 PM

Usage of Pattern.compile function in Java The Pattern.compile function in Java is a method used to compile regular expressions. Regular expression is a powerful string matching and processing tool that can be used to find, replace, verify strings and other operations. The Pattern.compile function allows us to compile a string pattern into a Pattern object, which can then be used to perform a series of string operations. Pattern.compi

PatternSyntaxException class in Java regular expressions PatternSyntaxException class in Java regular expressions Sep 11, 2023 pm 07:37 PM

The PatternSyntaxException class represents an unchecked exception thrown when a syntax error occurs in a regular expression string. This class contains three main methods namely - getDescription() - returns the description of the error. getIndex() - Returns the error index. getPattern() - Returns the regular expression pattern in which the error occurred. getMessage() - Returns the complete message containing the error, the index, the regular expression pattern in which the error occurred, and the error in the indicated pattern. Example Real-time demonstration importjava.util.Scanner;importjava.util.regex.Matcher;i

Use the replace() method of the StringBuilder class in Java to replace part of the content in a string Use the replace() method of the StringBuilder class in Java to replace part of the content in a string Jul 24, 2023 pm 10:28 PM

In Java, use the replace() method of the StringBuilder class to replace part of the content in a string. In Java programming, strings are a very important data type, and strings often need to be processed and manipulated. And sometimes we need to replace part of the string to meet our needs. In Java, you can use the replace() method of the StringBuilder class to implement string replacement operations. StringBuilder is a

How to use Pattern function in Java for pattern matching How to use Pattern function in Java for pattern matching Jun 26, 2023 pm 02:55 PM

In Java, the Pattern function is a very powerful and flexible tool that helps developers perform precise pattern matching in text. In this article, we will introduce how to use the Pattern function for pattern matching. The Pattern function is part of the Java.util.regex package, which allows developers to define and parse regular expressions. Regular expressions are a powerful tool for matching and manipulating text. It can be used to check the number and order of occurrences of letters, numbers, special characters, etc.

Google Pixel 9a: Leak points to larger casing and four colors Google Pixel 9a: Leak points to larger casing and four colors Oct 03, 2024 am 06:04 AM

The new design of the Google Pixel 9a has already been seen in initial photos and renders over the past few weeks, and nowAndroid Headlineshas just uncovered the exact dimensions and colors of the mid-range smartphone. The Pixel 9a measures 154 x 73

See all articles