Home >Backend Development >PHP Tutorial > 求好手写一段正则

求好手写一段正则

WBOY
WBOYOriginal
2016-06-13 12:52:58959browse

求高手写一段正则
需求:把一个字符串中的{liter}和{/liter}之间的内容提取出来(包括{literal}和{/literal}),然后md5加密后再放回原处

我是这样写的

<br />
<br />
$str="的分公司大哥reterty{literal}jpojp{/literal}ojojwr154654654wete梵{literal}蒂冈的身份{/literal}广东省rowetw";<br />
<br />
<br />
$new_str=preg_replace('/\{literal\}(.*?)\{\/literal\}/isum',md5("$1"),$new_str);<br />
print_r($new_str);<br />

但是这样的话 2个{liter}内的md5的值都一样,不知道哪里错了,请高手修改(还用preg_replace函数)


------解决方案--------------------
$new_str=preg_replace('/\{literal\}(.*?)\{\/literal\}/ise','md5("$1")',$str); 
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