bun 发表于 2012-08-10 18:30

linux_c_py_php 发表于 2012-08-11 12:14

$ php main.php
string(60) "hello, i'm 12345abcdef12345, this is my girlfriend hanmeimei"
$ cat main.php
<?php
$str = "hello, i'm abcdef, this is my girlfriend hanmeimei";
$res = preg_replace(array_pad(array(), 2, '/abcdef/'), array('12345\0', '${0}12345'), $str);
var_dump($res);
?>

maochanglu 发表于 2012-08-13 09:48

正则表达式里面 ^ 匹配最开始$匹配结尾
页: [1]
查看完整版本: 用preg_replace如何在字符传前后添加内容?