Re: using fwrite to create PHP files

From: Date: Fri, 05 Sep 2003 18:43:31 +0000
Subject: Re: using fwrite to create PHP files
References: 1 2  Groups: php.general php.general 
Request: Send a blank email to php-general+get-161816@lists.php.net to get a copy of this message
this is a sample of what I do when I need to write a php file $stringtowrite = "<?PHP\n// Bulletin Board forum\n$"."ForumId=".$tabletofind.";\n"; $stringtowrite .= "$"."ForumActive='1';\n$"."ForumName='".$sportname."';\n"; $stringtowrite .= "$"."ForumDescription='".$sportname." forum';\n"; $stringtowrite .= "$"."ForumConfigSuffix='';\n"; $stringtowrite .= "$"."ForumFolder='0';\n"; $stringtowrite .= "$"."ForumParent='0';\n"; $stringtowrite .= "$"."ForumLang='lang/english.php';\n"; --- and so on until finally $fd=fopen($final_destination,"w") or die ("file won't open"); /*if ($fd===false) { echo "file create failed"; exit(); //return; } */ fwrite($fd,$stringtowrite); fclose($fd); <-- snip --> > Vince LaMonica wrote: > > > I wish to use fwrite() to create a small PHP file. So far, when I attempt > > to do this, php parses the contents of the file that fwrite needs to > > create. Eg, I have this: > > > > $new_id = mysql_insert_id(); > > // create brand new file > > $new_file = fopen("/var/www/html/$sitename/$submitted_url", "w"); > > $new_file_content = "\n" > > ." <?php \n" > > ." if ($_GET['preview'] == \"y\") { \n" > > You need to escape the dollar signs in your string. > > ." if (\$_GET['preview'] == \"y\") { \n" > > -- > ---John Holmes... <-- snip --> Chris Sherwood

« previous php.general (#161816) next »