Example 1 — Read a Text File
Write a short message to a file and read it back as a string.
<?php
$path = sys_get_temp_dir() . '/codetofun_fgc.txt';
file_put_contents($path, 'Hello, CodeToFun!');
$text = file_get_contents($path);
echo $text, PHP_EOL;
echo 'Length: ', strlen($text), PHP_EOL;
unlink($path); How It Works
- file_put_contents() saves the message into a temporary file.
- file_get_contents() reads the whole file and returns it as a string.
- echo prints the text that was read.
- strlen() counts 17 characters, which matches the message.

