I am developing an application that installs a copy of WordPress locally. In the application I’m developing I want it to replace the database_name_here
in the wp-config-sample.php
, so that it has the correct name as well as the username and password. And when I copy the file to wp-config.php
the info is correct.
I have used
$test = htmlspecialchars(file_get_contents($wp_config_sample_file))
To get the contents of the wp-config-sample.php
file and tried to use
$var = array(
'database_name_here' => 'fred',
);
$wp_config = strstr($test, $var);
and no changes are made. I have also tried str_replace
which will work but it seems to ignore any matches that appear between the <?php ?>
tags.
So in summary, I’m trying to create a wp-config.php
file from wp-config-sample.php
programatically that contains the hostname, username and password instead of me going into the file structure and editing the file directly before I can start developing. My application is to manage multiple WordPress installations locally for development purposes.
I found this example on how to replace items on a string based on an associative array, it’s quite simple:
Maybe of interest: How to Create a Custom WordPress Install Package?