Home > Backend Development > PHP Tutorial > 求大神帮助,关于正则表达式的

求大神帮助,关于正则表达式的

WBOY
Release: 2016-06-23 14:11:37
Original
852 people have browsed it

	$str = "fsafsaf<{0}>54a<{1}>u7ygda<{2}>kklaoda<{3}>";	$char = array('a1','a2','a3','a4');	$pattern = '/<\{(\d*)\}>/';	$replacement = '$char[\\1]';		$newstr = preg_replace($pattern,$replacement,$str);		echo $newstr;
Copy after login


我想把$str 里面的依次替换为 $char数组对应下标的值,可按我上面的代码来做替换之后输出了 fsafsaf$char[0]54a$char[1]u7ygda$char[2]kklaoda$char[3] ,没有取到值,在这个问题上卡主了,跪求指点。。


回复讨论(解决方案)

$pattern = '// e';

$pattern = '// e';

非常感谢,这样写可以了,可以问下加个 e 代表什么意思吗 

eval 计算表达式串

eval 计算表达式串

明白了,再次感谢!!

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