use TYPO3\CMS\Core\Utility\GeneralUtility; $message = "Hello world!"; $path = 'file.txt'; GeneralUtility::writeFile($path, $message);
use TYPO3\CMS\Core\Utility\GeneralUtility; $data = array( 'name' => 'John Doe', 'age' => 30, 'email' => 'johndoe@example.com' ); $path = '/var/www/data.json'; GeneralUtility::writeFile($path, json_encode($data), 'utf-8');In this example, we're writing some data to a JSON file located at an absolute path (/var/www/data.json), and we're specifying an encoding of utf-8. We're also using the built-in PHP function json_encode to convert our data to JSON before writing it to the file. Package library: TYPO3\CMS\Core\Utility\GeneralUtility - This is a part of TYPO3 CMS's core utility library.