[quote] > Vince LaMonica wrote: >[quote] > > I wish to use fwrite() to create a small PHP file. So far, when I[/quote][/quote] attempt[quote][quote] > > 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" > > ." > ." if ($_GET['preview'] == \"y\") { \n"[/quote] > > You need to escape the dollar signs in your string. > > ." if (\$_GET['preview'] == \"y\") { \n" > > -- > ---John Holmes...[/quote] <-- snip --> Chris Sherwood [allowsmilie] => 1 [showsignature] => 0 [ipaddress] => [iconid] => 0 [visible] => 1 [attach] => 0 [infraction] => 0 [reportthreadid] => 0 [isusenetpost] => 1 [msgid] => <019201c373dd$9b0a3550$a200a8c0@CANCoaVan.cancoach.com> [ref] => <3F58D6D1.7050005@charter.net> [htmlstate] => on_nl2br [postusername] => Chris Sherwood [ip] => csherwood@norti [isdeleted] => 0 [usergroupid] => [membergroupids] => [displaygroupid] => [password] => [passworddate] => [email] => [styleid] => [parentemail] => [homepage] => [icq] => [aim] => [yahoo] => [msn] => [skype] => [showvbcode] => [showbirthday] => [usertitle] => [customtitle] => [joindate] => [daysprune] => [lastvisit] => [lastactivity] => [lastpost] => [lastpostid] => [posts] => [reputation] => [reputationlevelid] => [timezoneoffset] => [pmpopup] => [avatarid] => [avatarrevision] => [profilepicrevision] => [sigpicrevision] => [options] => [akvbghsfs_optionsfield] => [birthday] => [birthday_search] => [maxposts] => [startofweek] => [referrerid] => [languageid] => [emailstamp] => [threadedmode] => [autosubscribe] => [pmtotal] => [pmunread] => [salt] => [ipoints] => [infractions] => [warnings] => [infractiongroupids] => [infractiongroupid] => [adminoptions] => [profilevisits] => [friendcount] => [friendreqcount] => [vmunreadcount] => [vmmoderatedcount] => [socgroupinvitecount] => [socgroupreqcount] => [pcunreadcount] => [pcmoderatedcount] => [gmmoderatedcount] => [assetposthash] => [fbuserid] => [fbjoindate] => [fbname] => [logintype] => [fbaccesstoken] => [newrepcount] => [vbseo_likes_in] => [vbseo_likes_out] => [vbseo_likes_unread] => [temp] => [field1] => [field2] => [field3] => [field4] => [field5] => [subfolders] => [pmfolders] => [buddylist] => [ignorelist] => [signature] => [searchprefs] => [rank] => [icontitle] => [iconpath] => [avatarpath] => [hascustomavatar] => 0 [avatardateline] => [avwidth] => [avheight] => [edit_userid] => [edit_username] => [edit_dateline] => [edit_reason] => [hashistory] => [pagetext_html] => [hasimages] => [signatureparsed] => [sighasimages] => [sigpic] => [sigpicdateline] => [sigpicwidth] => [sigpicheight] => [postcount] => 6 [islastshown] => 1 [isfirstshown] => [attachments] => [allattachments] => ) --> using fwrite to create PHP files - PHP Development

using fwrite to create PHP files - PHP Development

Hi all, I wish to use fwrite() to create a small PHP file. So far, when I attempt to do this, php ps 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&prev iew=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 ...

  1. #1

    Default 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 ps 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&prev iew=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]vjluci.edu[/email] [url]http://www.seweb.uci.edu/techsupport[/url]

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

  2. #2

    Default Re: using fwrite to create PHP files

    To answer your question, you probably can do
    $new_file_content="<"."?"."php\n" . [...] . "?".">";

    But why in the world do you need this complication?

    Bogdan

    Vince Lamonica wrote:
    > Hi all,
    >
    > I wish to use fwrite() to create a small PHP file. So far, when I attempt
    > to do this, php ps 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&prev iew=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/
    >
    Bogdan Stancescu Guest

  3. #3

    Default Re: using fwrite to create PHP files


    Hi,

    Ik think the pr is teasing you.
    Try this workaround:

    $myphpopentag = "";
    $myphpopentag .= "<";
    $myphpopentag .= "?php";

    and use that $myphpopentag instead where needed.

    Try the same for the closetag.

    Hope that helps,

    regards,
    Erwin
    Erwin Moller Guest

  4. #4

    Default RE: [PHP] using fwrite to create PHP files

    Vince,
    You also need to escape the $, so instead of
    .." if ($_GET......
    use
    .." if (\$_GET.....

    You may have to escape the single quotes.

    I have written two pretty lame code generators. The first one did not use
    "templates", the second one does. You've got the lines of code in your
    "builder" script. I recommend moving those lines of code out, and put them
    into a template, then use str_replace() to change the template as/where
    needed.
    chris

    -----Original Message-----
    From: Vince LaMonica [mailto:vjlsoceco.uci.edu]
    Sent: Friday, September 05, 2003 1:20 AM
    To: PHP-General
    Subject: [PHP] 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 ps 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
    vjluci.edu 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
    Chris Hubbard Guest

  5. #5

    Default Re: [PHP] using fwrite to create PHP files

    Vince LaMonica wrote:
    > I wish to use fwrite() to create a small PHP file. So far, when I attempt
    > to do this, php ps 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...

    Amazon Wishlist: [url]www.amazon.com/o/registry/3BEXC84AB3A5E/[/url]

    php|architect: The Magazine for PHP Professionals [url]www.phparch.com[/url]
    John W. Holmes Guest

  6. #6

    Default Re: [PHP] using fwrite to create PHP files

    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 ps 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
    Chris Sherwood Guest

Similar Threads

  1. Create Adobe PDF files from PDF files?
    By David_H_BB@adobeforums.com in forum Adobe Acrobat Windows
    Replies: 1
    Last Post: May 3rd, 03:37 PM
  2. [PHP] using fwrite to create PHP files
    By Jay Blanchard in forum PHP Development
    Replies: 1
    Last Post: September 9th, 01:02 PM
  3. Is fwrite atomic or not?
    By Herouth Maoz in forum PHP Development
    Replies: 0
    Last Post: August 6th, 02:25 PM
  4. fwrite problem
    By s a n j a y in forum PHP Development
    Replies: 3
    Last Post: July 17th, 06:16 AM
  5. How to create help files / text files
    By Falcon in forum FileMaker
    Replies: 4
    Last Post: July 15th, 11:43 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139