Created
July 29, 2009 08:16
-
-
Save miknight/157929 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Replaces PHP function calls date_format() with date() and date_create() with strtotime() to maintain PHP 5.1 compatibility. | |
for file in `grep -Rin date_format * | grep -v '.svn' | grep -v 'convert.sh' | grep -v 'test.php' | cut -d: -f1 | sort -u`; do | |
echo "Replacing calls in $file"; | |
#ruby -pe 'gsub(/date_format\(date_create\((.+)\), \"(.+)\"\)/, "date(\"\\2\", strtotime(\\1))")' < $file > $file.temp1 | |
ruby -pe 'gsub(/date_create\((.+?)\)/, "strtotime(\\1)")' < $file > $file.temp1 | |
ruby -pe 'gsub(/date_format\((.+?), \"(.+?)\"\)/, "date(\"\\2\", \\1)")' < $file.temp1 > $file.temp2 | |
rm $file.temp1 | |
php -l $file.temp2 > /dev/null | |
if [[ $? == 0 ]]; then | |
echo "Successfully changed ${file}."; | |
mv $file.temp2 $file; | |
else | |
echo "Syntax error in ${file}.temp, deleting."; | |
rm $file.temp2 | |
fi; | |
done; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment