Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/253.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何用str_replace替换配置指令?_Php_Str Replace - Fatal编程技术网

Php 如何用str_replace替换配置指令?

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

我试图替换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'] = '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);