Jump to content

[SOLVED] Write a PHP file with PHP


Doqrs

Recommended Posts

thank you

 

how would i be able to get the <<<EOF heredoc stuff to work if i also want to have actual php code and not just text? I wasn't able to get it to work with this:

 

<?php
$contents = <<<EOF
header("location: somewhere");
EOF;

$fp = fopen("dir/{$time}.php", "w+");
fwrite($fp, $contents);
fclose($fp);
?>

Yep, that code snippet should work fine, as Doqrs says. Maybe you have some indentation in your real code that makes it fail, like :

if(smthing) {
  $contents = <<<EOF
  header("location: somewhere");
  EOF;
}

 

In this case, you will get an error, because you cant have spaces or tabs or anything other than "EOF;" on the EOF line.

 

If it's your fopen/fwrite that fails you should check file/folder permissions.

http://no2.php.net/manual/en/function.fopen.php

http://no2.php.net/manual/en/function.fwrite.php

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.