What are some best practices for writing PHP scripts that need to be compatible with both PHP 4.x and PHP 5?

When writing PHP scripts that need to be compatible with both PHP 4.x and PHP 5, it is important to avoid using deprecated functions or features that are no longer supported in newer versions of PHP. One approach is to use conditional statements to check the PHP version and then use alternative functions or syntax depending on the version.

if (version_compare(PHP_VERSION, '5.0.0', '<')) {
    // Code for PHP 4.x
} else {
    // Code for PHP 5.x
}