- foreach ($configFile as $line_num => $line) {
- switch (substr($line,0,16)) {
- case "define('DB_NAME'":
- fwrite($handle, str_replace("putyourdbnamehere", $dbname, $line));
- break;
- case "define('DB_USER'":
- fwrite($handle, str_replace("'usernamehere'", "'$uname'", $line));
- break;
- case "define('DB_PASSW":
- fwrite($handle, str_replace("'yourpasswordhere'", "'$passwrd'", $line));
- break;
- case "define('DB_HOST'":
- fwrite($handle, str_replace("localhost", $dbhost, $line));
+ $key = 0;
+ // Not a PHP5-style by-reference foreach, as this file must be parseable by PHP4.
+ foreach ( $config_file as $line_num => $line ) {
+ if ( '$table_prefix =' == substr( $line, 0, 16 ) ) {
+ $config_file[ $line_num ] = '$table_prefix = \'' . addcslashes( $prefix, "\\'" ) . "';\r\n";
+ continue;
+ }
+
+ if ( ! preg_match( '/^define\(\'([A-Z_]+)\',([ ]+)/', $line, $match ) )
+ continue;
+
+ $constant = $match[1];
+ $padding = $match[2];
+
+ switch ( $constant ) {
+ case 'DB_NAME' :
+ case 'DB_USER' :
+ case 'DB_PASSWORD' :
+ case 'DB_HOST' :
+ $config_file[ $line_num ] = "define('" . $constant . "'," . $padding . "'" . addcslashes( constant( $constant ), "\\'" ) . "');\r\n";