Home  >  Article  >  Backend Development  >  PHP 正则 ${1} 解释解决方法

PHP 正则 ${1} 解释解决方法

WBOY
WBOYOriginal
2016-06-13 13:31:071267browse

PHP 正则 ${1} 解释

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--><?php $string = 'aaaa3aaa6aaaa2aaaaaa0aaaaaa2aaa1a';

$pattern=array('/(\d)/i');
$replace=array('[${1}]');
echo $string."<br/>";
echo preg_replace($pattern, $replace, $string);
?> 


替换前:aaaa3aaa6aaaa2aaaaaa0aaaaaa2aaa1a
替换后:aaaa[3]aaa[6]aaaa[2]aaaaaa[0]aaaaaa[2]aaa[1]a
怎么个原理法啊?那个${1}如何解释啊?

------解决方案--------------------
是pattern里第一个括号的意思。
------解决方案--------------------
第一个子模式。即第一组()号的内容。
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