Hello, Can someone help me, i have a old script that i try to get working with php 7 I cant find the correct settings to replace this ereg line for preg_replace Code: $line = ereg_replace("(winning0=').*;","\\1".$winningform0."';",$line); The script is reading a file and than loops to it for changes that was made in a form. The arrays = Code: Array ( [setidform] => A- [winningform0] => on [...... ) Code: if (@file_exists("config/settings.php")){ $filearray=file("config/settings.php"); @$fp=fopen("config/settings.php","w"); print_r($filearray); while (list ($line_num,$line) = each ($filearray)) { echo "debug: ". winningform0; gives me a: debug: on The line in the settings.php file is: Code: $winning0='';
You just need to add slashes to the start and end of the pattern: Code: $ php <?php $line = "\$winning0='';"; $winningform0 = 'something'; $line = preg_replace("/(winning0=').*;/", "\\1${winningform0}';", $line); echo "line is: $line\n"; ^d line is: $winning0='something';