summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--write-to-file-using-ob.php17
1 files changed, 17 insertions, 0 deletions
diff --git a/write-to-file-using-ob.php b/write-to-file-using-ob.php
new file mode 100644
index 0000000..89a3553
--- /dev/null
+++ b/write-to-file-using-ob.php
@@ -0,0 +1,17 @@
+<?php
+
+ob_start();
+
+echo '<?php'; // this will go into our file
+// stop php from interpreting, now write content of file freely!
+?>
+echo 'hello, world!';
+
+<?php
+echo '?>'; // this will go into our file
+
+$content = ob_get_flush();
+file_put_contents('foo.txt', $content);
+
+?>
+