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 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"
." 
readfile(\"http://www.foo.bar/${'sitename'}.display?${'sitename'}id=$new_id&preview=y\");
 \n"
." } else { \n"
." readfile(\"http://www.foo.bar/${'sitename'}.display?${'sitename'}id=$new_id\"); \n"
." } \n"
." ?>";

write($new_file, $new_file_content);
fclose($new_file);

Note that $sitename is defined earlier in the script.

I know that $new_id and $sitename get expanded, as I tried this:

$new_file_content = "hello world. Look at my ${'sitename'}.display and my $new_id";

and the new file was created with the above text and the two vars
expanded. My problem lies in the fact that I need to put "<?php" tags
inside the contents of $new_file_content. I'm not sure how to do that w/o
generating lots of errors. As you can see in my above example, I've tried
to escape the double quotes, but that didn't seem to help. PHP insists on
processing the "if" line instead of ignoring it.

I'm running 4.3.3 under apache 1.3.28.

Any help would be most appreciated!

/vjl/

-- 
Vince LaMonica               UC Irvine,  School  of  Social Ecology
 W3 Developer       <*>      116 Social Ecology I, Irvine, CA 92697
 [EMAIL PROTECTED]                  http://www.seweb.uci.edu/techsupport

 Tower: "Delta Zulu Romeo, turn right now and report your heading."
 Pilot: "Wilco. 341, 342, 343, 344, 345..."

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to