Home > Backend Development > PHP Tutorial > 求大神把{my:abc} 正则匹配成 <my name="abc" />

求大神把{my:abc} 正则匹配成 <my name="abc" />

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-23 13:29:13
Original
964 people have browsed it

把{my:abc} 正则匹配成 

$content = '{my:abc}{my:CBA}{my:123}{sys:abc}{field:CBA}{tag:aaa}';


 发现这样写无效 求大神修正 
$content = preg_replace('/{(\w.+):(\w.+)}/i', '',$content);


只有my: sys: fled:开头的匹配,其他的不匹配 
希望得到的匹配结果是

{tag:aaa}

请务必测试可行后回复  谢谢


回复讨论(解决方案)

echo preg_replace('/\{(my|sys|field)\:(\w+)\}/', '<$1 name="$2" />',$content);
Copy after login
Copy after login
Copy after login

echo preg_replace('/\{(my|sys|field)\:(\w+)\}/', '<$1 name="$2" />',$content);
Copy after login
Copy after login
Copy after login


没有任何变化 匹配不成功
原始:{my:abc}{my:CBA}{my:123}{sys:abc}{field:CBA}{tag:aaa}
结果:{my:abc}{my:CBA}{my:123}{sys:abc}{field:CBA}{tag:aaa}

结果:{tag:aaa}

$content = '{my:abc}{my:CBA}{my:123}{sys:abc}{field:CBA}{tag:aaa}';$content = preg_replace('/{(my|sys|field):(\w.+)}/iU', '<$1 name="$2" />',$content);echo $content;
Copy after login
{tag:aaa}


echo preg_replace('/\{(my|sys|field)\:(\w+)\}/', '<$1 name="$2" />',$content);
Copy after login
Copy after login
Copy after login


没有任何变化 匹配不成功
原始:{my:abc}{my:CBA}{my:123}{sys:abc}{field:CBA}{tag:aaa}
结果:{my:abc}{my:CBA}{my:123}{sys:abc}{field:CBA}{tag:aaa}
你是怎么看的,要在源码下看才能看到效果。

抱歉 是我SB了  已OK 万分感谢!

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