Hey all,

i'm working on some code and i've got a little problem.

$my_file = 'file.php';
$newline = "<?php $root = '"$mylocation"/'; ?>";
file_put_contents($my_file, $newline);

As you can see i want to post a line into a file.. The problem is, this file will output:

<?php = 'your location'; ?>

the $root is gone..
Please help me.
Thanks

Well that is because you use double quotes, and any PHP variable typed plainly within double quotes will take and output the value of that variable. In other words, if $root = NULL, it will output empty space if used inside double quotes. If you want to output literally "$root" instead of its value AND you're using double quotes, type it as follows:

$newline = "<?php \$root = '"$mylocation"/'; ?>";

(I've prepended a backslash to $root).

Oke, i now did it by using database because it saved me time,
but i'll try it so thx anyway!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.