How can PHP scripts be written to ensure compatibility with safe-mode restrictions?

When writing PHP scripts to ensure compatibility with safe-mode restrictions, it is important to avoid using functions or features that are restricted by safe mode, such as exec(), system(), passthru(), shell_exec(), etc. Instead, use alternative methods or functions that are safe-mode friendly, such as using the PHP built-in functions for file operations like fopen(), fwrite(), etc.

// Example of safe-mode friendly file writing
$file = 'example.txt';
$data = 'Hello, World!';
$handle = fopen($file, 'w');
fwrite($handle, $data);
fclose($handle);