I need to use php to find and replace the database in a config file:
$cfg['database'] = 'my_database_name';
Basically, I'm trying to figure out a regular expression that would find everything between
$cfg['database'] =
and
;
then replace it with the actual database name. I think I would need to use preg_replace and then use the matches开发者_Go百科 array, but I'm having a hard time trying to make it work.
Can someone give me an idea of how to go about this, or point me to a good resource that would address this specific type of replacement situation?
preg_replace('/(\$cfg\[\s*\'database\'\s*]\s*=\s*\').*(\'\s*;)', '$1' . $dbName . '$2', $text);
精彩评论