- 论坛徽章:
- 1
|
[quote]原帖由 dz902 于 2005-11-4 00:22 发表
应该是
- $strSource = "bb1";
- $strReplace = "replaced"; // this line's added
- $strResult = preg_replace('/^(aa|bb).+?$/', "\$1{$strReplace}", $strSource); ... [/quote]
- 偶,看错了LZ的要求:
- [code]
- <?php
- // --------------------------------------------------------------------------
- // File name : 文件名称.php
- // Description : 文件说明
- // Requirement : PHP4 (http://www.php.net)
- //
- // Copyright(C), HonestQiao, 2005, All Rights Reserved.
- //
- // Author: HonestQiao (honestqiao@hotmail.com)
- //
- // --------------------------------------------------------------------------
- $strSource = "aa";
- $strReplace = "replaced";
- $strResult = preg_replace('/^(aa|bb)(.+?)$/', "$1$strReplace", $strSource);
- echo $strResult;
- $strSource = "bb";
- $strReplace = "replaced";
- $strResult = preg_replace('/^(aa|bb)(.+?)$/', "$1$strReplace", $strSource);
- echo $strResult;
- $strSource = "aa1";
- $strReplace = "replaced";
- $strResult = preg_replace('/^(aa|bb)(.+?)$/', "$1$strReplace", $strSource);
- echo $strResult;
- ?>
复制代码
- ---------- PHP代码调试 ----------
- Content-type: text/html
- X-Powered-By: PHP/4.3.10
- aa
- bb
- aareplaced
- 输出完成 (耗时 0 秒) - 正常终止
复制代码 |
|