nadeemshafi9 Posted August 27, 2006 Share Posted August 27, 2006 hi guys i need to write the entire following code to a file using fwrite()[code]$data = ""."<?php"."$i = 'hello'"."print $i;"."?>";$i=fopen(file)fwrite($i,$data)[/code]i tried leading and trailing backslashes and double backslashes they reduce the prob but dont eradicate it. the slashes appear in the filethanks for any helpNadeem Quote Link to comment https://forums.phpfreaks.com/topic/18830-write-php-code-using-fwrite/ Share on other sites More sharing options...
wildteen88 Posted August 27, 2006 Share Posted August 27, 2006 Use HEREDOC syntax:[code=php:0]$data = <<<PHP<?php\$i = 'hello';print \$i;?>PHP;$i = fopen(file);fwrite($i, $data);[/code] Quote Link to comment https://forums.phpfreaks.com/topic/18830-write-php-code-using-fwrite/#findComment-81276 Share on other sites More sharing options...
nadeemshafi9 Posted August 27, 2006 Author Share Posted August 27, 2006 hi i tried ur sugestion it didnt work but i read up on the heredoc syntax on php.net and it said in cases like mine i can also use single quotes which work well.thancks though this heredoc syntax looks interesting and is new to me iim glad u brought it upthanks Quote Link to comment https://forums.phpfreaks.com/topic/18830-write-php-code-using-fwrite/#findComment-81312 Share on other sites More sharing options...
wildteen88 Posted August 27, 2006 Share Posted August 27, 2006 HEREDOC is very html for large text/html code blocks. Saves you having to escape quotes etc. But alot of people dont know this syntax exists. Quote Link to comment https://forums.phpfreaks.com/topic/18830-write-php-code-using-fwrite/#findComment-81326 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.