askbapi Posted April 9, 2009 Share Posted April 9, 2009 I want to create a PHP file in runtime. That mean a php script(a.php) will create another php file (b.php) and php file (b.php) can also run later. Php file (b.php) should have php code. Can it be done? If yes, Pls say how! Quote Link to comment https://forums.phpfreaks.com/topic/153330-solved-create-php-file-in-runtime/ Share on other sites More sharing options...
Maq Posted April 9, 2009 Share Posted April 9, 2009 You would need to use fopen and fwrite. Quote Link to comment https://forums.phpfreaks.com/topic/153330-solved-create-php-file-in-runtime/#findComment-805548 Share on other sites More sharing options...
askbapi Posted April 9, 2009 Author Share Posted April 9, 2009 fwrite() and fopen() both work fine while writing simple text. BUT how can i WRITE php code in the created file. For example : >I have created php file with fwrite. >Now i want to write code like this "include_once($ram."db.php")" in to the file. Quote Link to comment https://forums.phpfreaks.com/topic/153330-solved-create-php-file-in-runtime/#findComment-805564 Share on other sites More sharing options...
daniel244rock Posted April 9, 2009 Share Posted April 9, 2009 $createfile = "newfile.php"; $fh = fopen($createfile, 'w'); fwrite($fh, "<?PHP \n include_once(\$ram.\"db.php\")\n ?>"); I think that should work to write that file you were wanting. Lemme check it though. alright, now it works fine. Quote Link to comment https://forums.phpfreaks.com/topic/153330-solved-create-php-file-in-runtime/#findComment-805578 Share on other sites More sharing options...
askbapi Posted April 10, 2009 Author Share Posted April 10, 2009 Thank you, My problem is solved! Quote Link to comment https://forums.phpfreaks.com/topic/153330-solved-create-php-file-in-runtime/#findComment-806290 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.