Home > Backend Development > PHP Tutorial > 怎么将网页中指定的字符串标红

怎么将网页中指定的字符串标红

WBOY
Release: 2016-06-13 11:49:30
Original
1953 people have browsed it

如何将网页中指定的字符串标红?
各位大神,我想在一个输出的字符中,将里面有一个字符串和它后面跟着一个空格之后的字符串标红,不知道大家有没有什么好的建议?我是用PHP写的。关键的字符串,我都能获得。比如说:源字符串是 I come from China! 我想要的是,我知道come这个关键的字,后面的from不知道。我想将 come 和 from 都标红!不知道,大家有没有什么好的看法? 
------解决方案--------------------

$s = 'I come from China!';<br />echo preg_replace('/come\s\w+/', '<font color=red>$0</font>', $s);
Copy after login
come from China!

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template