정규식을 사용하여 문자열을 대체 할 수있는 완벽한 예입니다. preg_replace 함수를 확인하십시오. $ 패턴이 정규식에
<?php
$contents = file_get_contents("your file name");
preg_replace($pattern, $replacement, $contents);
$fh = fopen("your file name", "w");
fwrite($fh, $contents);
?>
입니다 : 당신이 정규 표현식을 사용하는 방법을 아주 확실하지 않은 경우 당신은
here 그냥 당신이 그런 짓을해야합니다 명확히 할 수있는 좋은 자습서를 찾을 수 있습니다 $ 대체는 대체 값입니다.
그래서 그때 내 변화를 만드는 infromation을 모두 얻을 전체 파일
function config_set($config_file, $section, $key, $value) {
$config_data = parse_ini_file($config_file, true);
$config_data[$section][$key] = $value;
$new_content = '';
foreach ($config_data as $section => $section_content) {
$section_content = array_map(function($value, $key) {
return "$key=$value";
}, array_values($section_content), array_keys($section_content));
$section_content = implode("\n", $section_content);
$new_content .= "[$section]\n$section_content\n";
}
file_put_contents($config_file, $new_content);
}
를 다시 작성에 fwrite를 사용하도록 parse_ini_file을 사용 : – irishwill200