You need to open and read the file and then rewrite the contents. Something like this (has not been tested)...
PHP Code:
$new_value = "6";
$new_file = "";
$handle = @fopen("y.php", "r");
if ($handle) {
while (!feof($handle)) {
$buffer = fgets($handle, 4096);
if(stristr($buffer,'$a' !hahahaha FALSE)){
$new_file .= "$a = ".$new_value."\"";
} else {
$new_file .= $buffer;
}
fclose($handle);
}
$handle = @fopen("y.php", "w");
if($handle){
fwrite($handle,$new_file);
}