Php 如何用str_replace替换配置指令?
我试图替换phpmyadmin ini文件中的配置选项,但没有替换任何选项。我尝试了几种逃避模式和替换的组合,但我不知道我做错了什么Php 如何用str_replace替换配置指令?,php,str-replace,Php,Str Replace,我试图替换phpmyadmin ini文件中的配置选项,但没有替换任何选项。我尝试了几种逃避模式和替换的组合,但我不知道我做错了什么 <?php $pattern = '$cfg[\'Servers\'][$i][\'auth_type\'] = \'cookie\';'; $replacement = '$cfg[\'Servers\'][$i][\'auth_type\'] = \'http\';'; $sContents = '$cfg[\'Servers\'][$i][\'a
<?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'] = 'http';
非常感谢您的帮助。这应该行得通
$pattern = 'cookie';
$replacement = 'http';
$return = str_replace($pattern, $replacement, $sContents);
die($return);
您需要使用ini_set来更改php ini文件中的选项
您没有保存
str\u replace
的结果。只要这样做,即使没有@Mário的简短版本,它也能工作:
$sContents = str_replace($pattern, $replacement, $sContents);
die($sContents);
我太累了!!我没有看到我忘记将str_replace输出放在$sContents变量--'
$sContents = str_replace($pattern, $replacement, $sContents);
die($sContents);