preg_replace 替换值有子表达式值加数值有关问题

WBOY
Release: 2016-06-13 11:53:26
Original
930 people have browsed it

preg_replace 替换值有子表达式值加数值问题

本帖最后由 panlvfei 于 2014-04-02 15:31:02 编辑 如下面简单的替换:
$ih=100;
$aa='a123b';
$aa=preg_replace('/^(a)123(b)$/i','$1'.$ih.'$2',$aa);
print_r($aa);
怎么结果就是不对,$ih变为字母就正常,数字的话会丢第一位和$1。在$1随便加个字母也正常,不会是我电脑问题吧?
------解决方案--------------------
$aa=preg_replace('/^(a)123(b)$/ie','"$1".$ih."$2"',$aa);
Copy after login

------解决方案--------------------
<br />$ih=500;<br />$aa='a123b';<br />$aa=preg_replace('/^(a)123(b)$/i','${1}'.$ih.'${2}',$aa);<br />print_r($aa);<br />
Copy after login
Related labels:
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