1

嗨,我想替换单引号内的文本

$key = 'ABC';

我写了这段 PHP 代码:

$data = '$key = \'ABC\'';
preg_match($data, '/s$key = \'(.*)\'\;/s', $security_key);
print_r($security_key); 

但它会发出警告,例如 Warning: preg_match() [function.preg-match]: No ending matching delimiter '>'

4

2 回答 2

2
$data = '$key = \'ABC\'';
$replacement = 'CBA';
$data = preg_replace("/'[^']*'/", "'$replacement'", $data);
var_dump($data);
于 2012-04-29T07:29:52.060 回答
0

正则表达式必须以分隔符开头和结尾- %,/,$,#,~...

试试这个:

$data = '%$key = \'ABC\'%';
preg_match($data, '/s$key = \'(.*)\'\;/s', $security_key);
print_r($security_key);
于 2012-04-29T05:15:52.070 回答