Home > Backend Development > PHP Tutorial > 正则替换表情,伤不起,求帮助

正则替换表情,伤不起,求帮助

WBOY
Release: 2016-06-23 13:57:14
Original
931 people have browsed it

有这样这样两个数组
$arr=Array ( 0 => 微笑 ,1 => 色 , 2=>撇嘴 )
$brr=array(1 , 2 , 3)

如何把下面这个字符串里的表情符号替换成$brr里面的值呢?因为这样方便我组成1.gif 2.gif,,,,,正则不会哇。。。
$content='a[色]fdsafd[撇嘴]saf[微笑]b


回复讨论(解决方案)

$arr=Array ( 0 => '微笑' ,1 => '色' , 2=>'撇嘴' );$brr=array(1 , 2 , 3);$content='a[色]fdsafd[撇嘴]saf[微笑]b';foreach($arr as &$v) $v = "/\\[$v\\]/";foreach($brr as &$v) $v = "<img  src='$v.gif' alt="正则替换表情,伤不起,求帮助" >";$content = preg_replace($arr, $brr, $content);echo $content;
Copy after login
a正则替换表情,伤不起,求帮助fdsafd正则替换表情,伤不起,求帮助saf正则替换表情,伤不起,求帮助b

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