How to write codes in a file using php -


i want write php codes in file using php

try

$cache = "<?php include_once 'a.php';" . $var .ob_get_contents(); file_put_contents('page.php', $cache); 

error

syntax error, unexpected '' (t_encapsed_and_whitespace), expecting identifier (t_string) or variable (t_variable) or number (t_num_string) 

thank you

your syntax wrong, have try instead started:

<?php $cache = file_get_contents('a.php'); file_put_contents('page.php', $cache); 

the documentation of file_put_contents() states requires two arguments (or more). first path file write to, second content write file. provided single argument, since concatenated 2 things using . operator.

however in case: wouldn't easier copy file instead?

your comment below suggests indeed want concatenate variables value write output file. concatenate then:

<?php $cache = file_get_contents('a.php'); $cache .= $var; $cache .= ob_get_contents(); file_put_contents('page.php', $cache); 

Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -