0

Here is what I have so far

file_put_contents('./'. $dir .'/'. file .'.php','<?php include "../head.php"; echo $head; ?>' . $body);

I also tried

file_put_contents('./'. $dir .'/'. file .'.php','<?php include "../head.php"; ?>' . $body);

and then echo $head; in the /head.php

I want a head.php that is called by each of the generated files. There for I need to insert the php code <?php include "../head.php"; ?> on top of the files. with the given code <?php include "../head.php"; ?> it shows  on top.

head.php

echo '<html>...';
echo $_SERVER['REQUEST_URI'];
...

The issue is, it shows . I don't think this is a dupe.

5
  • you want to add a line to the top of a file? Commented Jul 25, 2019 at 21:05
  • that's right, or append the bod.php part, either way. Commented Jul 25, 2019 at 21:13
  • Possible duplicate of Need to write at beginning of file with PHP Commented Jul 25, 2019 at 21:14
  • it is not that i can not write to a file. it is that the code <?php include "../head.php" ?> does not appear in the file. how would prepending make a difference? Commented Jul 25, 2019 at 21:23
  • "not that i can not write to a file" "it is that the code .. does not appear in the file" sorry they seem to contradict, I'm totally lost. Commented Jul 25, 2019 at 21:36

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.