Home  >  Article  >  php教程  >  PHP正则实例:把字符串中的汉字替换为红色

PHP正则实例:把字符串中的汉字替换为红色

WBOY
WBOYOriginal
2016-06-07 11:34:441442browse

PHP正则实例:把字符串中的汉字替换为红色
PHP里使用正则表达式的一个经典实例:把字符串中的汉字替换为红色!
如果我们要用PHP把字符串中的汉字替换为红色,那么就应该想到有俩个过程:
第一就是用正则提取到字符串中的汉字,第二才是给这些汉字加上样式,看下面的实例:
PHP正则实例:把字符串中的汉字替换为红色

$string="I Love 黑帽联盟www.heimaolianmeng.com";
echo preg_replace("/([\x80-\xff]+)/","\\1",$string);
?>

AD:真正免费,域名+虚机+企业邮箱=0元

Statement:
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