SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Thread: fwrite error

  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2005
    Posts
    93
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    fwrite error

    $handle = fopen($filename,"w");
    chmod($filename, 0755);
    fwrite($handle, "<?php $keyword = 'something';");
    fwrite.($handle, "include($_SERVER['DOCUMENT_ROOT'].'/test.php'); ?>");

    when i do fwrite "test" it writes "test" in the file and it works. but when i try the above, it gives me an error. how would i make it so it would write

    PHP Code:
    <?php 
    $keyword 
    'something'
    include(
    $_SERVER['DOCUMENT_ROOT'].'/test.php'); 
    ?>
    <--- this is what i would like to write in the file

  2. #2
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try:
    PHP Code:
    $out = <<<EOD
    <?php
    \$keyword 'something';
    include(\
    $_SERVER['DOCUMENT_ROOT'].'/test.php');
    ?>
    EOD;
    $handle = fopen($filename,"w");
    chmod($filename, 0755);
    fwrite($handle, $out);
    fclose($handle);

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2005
    Posts
    93
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i get this error:

    Parse error: parse error, unexpected $ in /home/username/public_html/rich/tester.php on line 114

    line 114 contains "?>"

    i tried removed the "?>" at the end, but i still get the error. is there any way to fix this?

  4. #4
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have you escaped all the $'s as in the example above?
    E.g: \$foo = 'hello';

  5. #5
    SitePoint Enthusiast
    Join Date
    Nov 2005
    Posts
    93
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    escape everything in the whole file?

    or just between <<<EOD and EOD;?

    if your talking in between the EOD. then yes, i already escaped them

  6. #6
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can you post your example file or if it's too big then just the code in the EOD bit.

  7. #7
    SitePoint Enthusiast
    Join Date
    Nov 2005
    Posts
    93
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    got it working somehow, dont really know what i did. thanks alot


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
  •