2013-03-12 24 views
0

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

我使用這個功能:

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

在由$文件所表示的PHP文件替換

$uid=*any digit* 

它完美,當我匹配的基本模式,但

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

不會出於某種原因。

回答

1

保護$,作爲\$這個數字是單獨的嗎?可以是\d+

簡單示例:

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

輸出:

123 uid lalalatestest space was here