<?php $filename = 'file1.js'; if(file_exists($filename)) { echo '<script type=\"text\/javascript\" src=\"'.$filename.'\.js\"><\/script>'; } else { echo '<script type=\"text\/javascript\" src=\"file2\.js\"><\/script>'; } ?>