Hello all,
I am finding a line in a PHP file using PHP and writing to it by changing a variable at a particular line. Please see function below.
This works fine when I test it on its own. However, when I run it within my main script it doesn't work properly. I find the following sort of thing on = "Version_3_18110";
in the PHP file when it should be $version = "Version_3_18110";
Can this function be effected by echos further up the main script?? The string passed in as $version
is always what I need it to be, it just doesn't get written correctly.
What is going on?
function edit_config_version($version){
$version = trim($version);
$file = fopen("../includes/db-connect.php", "r") or exit("Unable to open file!");
$count = 0;
while(!feof($file)){
$line = fgets($file);
if(substr($line, 0, 10)=='$version ='){
$line_number = $count;
}
$count++;
}
fclose($file);
$count = 0;
$file = fopen("../includes/db-connect.php", "r+") or exit("Unable to open file!");
while(!feof($file)){
if($line_number==$count){
fwrite($file, '$version = "Version_'.$version.'";'."\r\n");
}
$line = fgets($file);
$count++;
}
fclose($file);
}
Contenets of db_connect.php:
/*
* Date: 06/10/09
* Last Updated: 06/04/2010
*/
$serverName = 'ABS-PC';
$monitor_name = "BTSH_Mon_3_18111";
$version = "Version_3_18112";
$full_url = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
$full_url = explode('view-report.php', $full_url);
$sitePath = $full_url[0];
$full_url = dirname('http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']).'/';
$sitePathFolder = $full_url;
/*
* Make sure to close the connection in the scripts
* sqlsrv_close( $conn);
*/