$file = './example.txt'; $handle = fopen($file, 'r'); if ($handle) { $content = fread($handle, filesize($file)); echo $content; fclose($handle); }
$file = './example.txt'; $handle = fopen($file, 'w'); if ($handle) { fwrite($handle, 'Hello World!'); fclose($handle); }In this example, we are using `getResource` to open the file `example.txt` in write mode. After opening the file, we are writing the string `Hello World!` to it using `fwrite`. Finally, we are closing the file using `fclose`. Package Library: The `getResource` function is a core PHP function and is not part of any package library. It is available in all versions of PHP.