PHP超强的模板替换函数

$string = ‘ajas{q111}ashdfkhask{w222}askdfhak{e333}aksjdfha{e333}kdfhkashdfkjashdfjkhasdkfjhaskjdfhaskdhfaskjdfhasjkdfhksdhbcdef’;

$pattern = ‘/\{([a-z|A-Z|_][a-z|A-Z|0-9|_]+?)\}/e’;

 

$q111 = ‘11111′;

$w222 = ‘2222′;

$e333 = ‘3333′;

$e333 = ‘4444′;

 

 

 

echo preg_replace($pattern, ‘${‘ . ‘\\1′ . ‘}’, $string);

Written by gegewan on 一月 22nd, 2010 with 1 comment.
Read more articles on 谈天说地.

Related articles

1 comment

Read the comments left by other users below, or:

Get your own gravatar by visiting gravatar.com 博百优
#1. 四月 30th, 2010, at 11:11 上午.

这个正则表达式不错,收藏了

Leave your comment...

If you want to leave your comment on this article, simply fill out the next form:




You can use these XHTML tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> .