0

基本上,我需要替换 php 文件中的文本,以便稍微更改 mysqli 查询。

我正在使用这个功能:

file_put_contents($file,preg_replace('/^($uid=)[\d]/', '$uid=' . $uid, file_get_contents($file)));

取代

$uid=*any digit*

在 $file 所代表的 php 文件中。

当我匹配基本模式时它工作得很好,但是

'/^($uid=)[\d]/'

由于某种原因不起作用。

4

1 回答 1

1

保护$,因为\$数字是单独的?或许\d+

简单示例:

<?php
$string="\$uid=123testest space was here";
echo preg_replace('/^\$uid=(\d+)/','$1 uid lalala',$string);

输出:

123 uid lalalatestest space was here
于 2013-03-12T02:00:25.433 回答