1

i want to create a config.inc.php file. which I am able to do. with just one problem. I can't create variables in the created PHP file.

here's what I did.

<?php 
$f = fopen('config.inc.PHP' , 'w');
fwrite($f, '<?php  $name = "odd";?>'); 
?>

the file is created fine but with an $name is an undefined variable error message and in the config.inc.PHP file u only see

     <?php =" odd "; ?>. what can I do?
Barmar
  • 741,623
  • 53
  • 500
  • 612
difrent
  • 11
  • 2
  • 2
    I can't reproduce the problem, your code works perfectly for me. Are you sure you copied it exactly as written? What you show would happen if you have the string in double quotes instead of single quotes. – Barmar Mar 03 '16 at 21:24
  • See http://stackoverflow.com/questions/3446216/what-is-the-difference-between-single-quoted-and-double-quoted-strings-in-php – Barmar Mar 03 '16 at 21:25
  • thanks it works fine now with the \ before the variable – difrent Mar 03 '16 at 21:32
  • That shouldn't be necessary if you have the string in single quotes as you've shown. – Barmar Mar 03 '16 at 21:32
  • that's true I see my error. – difrent Mar 03 '16 at 21:37

0 Answers0