Ask a Question related to PHP Development, Design and Development.
-
Jay Blanchard #1
RE: [PHP] using fwrite to create PHP files
[snip]
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:
[/snip]
Vince I did this
<?php
/*
** Write PHP with PHP
** 2003-09-05
*/
$newphp = fopen("/usr/server/test/new_php.php", "w");
fputs($newphp, "<?php\n");
fputs($newphp, "This is a PHP by PHP writing test.\n");
fputs($newphp, "?>\n");
fclose($newphp);
?>
And it worked fine. fputs() places the string in the file properly. I
also noticed at the end of your script....
write($new_file, $new_file_content);
Since I saw no write() function in your script I would have to assume
that you are calling an undefined function, which is probably where your
errors are coming from. Try changing the line to
fputs($new_file, $new_file_content);
And you should have much luck. Have a pleasant, productive and
meaningful day.
Jay Blanchard Guest
-
Create Adobe PDF files from PDF files?
Is is possible to create PDF files from an existing PDF file? For example, I have a PDF file that contains 2 pages of content. ("pages1and2.pdf")... -
using fwrite to create PHP files
Hi all, 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... -
Is fwrite atomic or not?
I've seen answers both ways in the archive of this list, and I wonder what is true. Suppose I open a file in append mode - like a log file. Two... -
fwrite int or float
Is there some easy way to fwrite a 32 bit int or float? -- Ted Huntington Programmer Analyst I Main Library University of California, Irvine... -
How to create help files / text files
I want to create a help dialogue that will just act as a reminder on do's & dont's I had in mind a text file with sliding bars but don't seem to... -
Mike Ford #2
RE: [PHP] using fwrite to create PHP files
On 05 September 2003 19:44, Chris Sherwood wrote:
Ouch! This looks like a prime candidate for a heredoc ([url]http://www.php.net/language.types.string#language.types.string.syntax .heredoc):[/url]> 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);
$stringtowrite = <<<STRINGTOWRITE
// Bulletin Board forum
\$ForumId=$tabletofind;
\$ForumActive='1';
\$ForumName='$sportname';
\$ForumDescription='$sportname forum';
\$ForumConfigSuffix='';
\$ForumFolder='0';
\$ForumParent='0';
\$ForumLang='lang/english.php';
STRINGTOWRITE;
You can even embed the heredoc directly in the fwrite():
$fd=fopen($final_destination,"w") or die ("file won't open");
fwrite($fd, <<<FILECONTENT
// Bulletin Board forum
\$ForumId=$tabletofind;
\$ForumActive='1';
\$ForumName='$sportname';
\$ForumDescription='$sportname forum';
\$ForumConfigSuffix='';
\$ForumFolder='0';
\$ForumParent='0';
\$ForumLang='lang/english.php';
FILECONTENT
);
fclose($fd);
Cheers!
Mike
---------------------------------------------------------------------
Mike Ford, Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS, LS6 3QS, United Kingdom
Email: [email]m.ford@lmu.ac.uk[/email]
Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211
Mike Ford Guest



Reply With Quote

