I have some (simplified) PHP config for a DB connection.
<?php
/*
<CONFIG application="Example" version="1.1">
<Database>
<Driver>MYSQL</Driver>
<Host>http://example.com</Host>
<Port>3306</Port>
<Database>qwerty</Database>
<Username>usr</Username>
<Password>hackme</Password>
</Database>
</CONFIG>
*/
?>
How can I populate the host, in the comments with a variable from an array, $serv["host"]
Here's my attempt...
<?php $serv["host"] = "http://example.com"; ?>
<?php
/*
<CONFIG application="Example" version="1.1">
<Database>
<Driver>MYSQL</Driver>
<Host>$serv["host"]</Host>
<Port>3306</Port>
<Database>qwerty</Database>
<Username>usr</Username>
<Password>hackme</Password>
</Database>
</CONFIG>
*/
?>
I've tried various concatenation and echo combinations, but it either doesn't compile properly or prints out my DB connection details. I need to keep these comments because the code I'm editing seems to require it.
<?php
$serv = array(
'host' => 'http://example.com';
);
?>
<CONFIG application="Example" version="1.1">
<Database>
<Driver>MYSQL</Driver>
<Host><?php echo $serv['host']; ?></Host>
<Port>3306</Port>
<Database>qwerty</Database>
<Username>usr</Username>
<Password>hackme</Password>
</Database>
</CONFIG>
You could make PHP create a file consisting of your commented out (out-commented?) code and include it then.
<?php $serv["host"] = "http://example.com"; ?>
<?php
$dbcon = "
/*
<CONFIG application="Example" version="1.1">
<Database>
<Driver>MYSQL</Driver>
<Host>" . $serv["host"] . "</Host>
<Port>3306</Port>
<Database>qwerty</Database>
<Username>usr</Username>
<Password>hackme</Password>
</Database>
</CONFIG>
*/";
$f = fopen("comment.php", 'w');
fwrite($f, $dbcon);
fclose($f);
include("comment.php");
?>
You might have to adjust destination and include paths as well as file system permissions, of course. Make sure that it's not readable/guessable from the document root, though. I'd be interested to hear if that actually works.