What are the best practices for writing PHP scripts that are compatible with both PHP4 and PHP5 versions?

When writing PHP scripts that need to be compatible with both PHP4 and PHP5 versions, it is important to avoid using features that are specific to only one version. This can include functions or syntax that were introduced in PHP5 but are not available in PHP4. To ensure compatibility, you can use conditional statements to check the PHP version and use alternative code if necessary.

if (version_compare(PHP_VERSION, '5.0.0', '>=')) {
    // PHP5 compatible code here
} else {
    // PHP4 compatible code here
}