我正在尝试替换phpmyadmin ini文件中的配置选项,但没有任何内容被替换。我尝试了几种逃避模式和替换的组合,但我无法弄清楚我做错了什么。
<?php
$pattern = '$cfg[\'Servers\'][$i][\'auth_type\'] = \'cookie\';';
$replacement = '$cfg[\'Servers\'][$i][\'auth_type\'] = \'http\';';
$sContents = '$cfg[\'Servers\'][$i][\'auth_type\'] = \'cookie\';';
str_replace($pattern, $replacement, $sContents);
die($sContents);
此代码段的输出为:
$cfg['Servers'][$i]['auth_type'] = 'cookie';
获得以下输出的正确模式和替换是什么?
$cfg['Servers'][$i]['auth_type'] = 'http';
非常感谢你的帮助。
答案 0 :(得分:1)
这应该有效
$pattern = 'cookie';
$replacement = 'http';
$return = str_replace($pattern, $replacement, $sContents);
die($return);
答案 1 :(得分:0)
您需要使用ini_set来更改php ini文件中的选项。
答案 2 :(得分:0)
您没有保存str_replace
的结果。只需这样做就可以了,即使没有@Mário的简短版本:
$sContents = str_replace($pattern, $replacement, $sContents);
die($sContents);