Marius van Witzenburg "Learned my lesson in life, now setting my action to stay in life."

3Mar/101

Easy replace php short open tags with long php open tags

I wrote a quite simple script to fix short open tags to long open tags.

This script is compatible with CakePHP 1.1 and 1.2, on request :-)

Have fun using it!

I suggest saving this file to /usr/local/bin/php_fix_short_open_tag

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/bin/sh
# Written by Marius van Witzenburg <info@mariusvw.com>
 
path="."
if [ ! -z "$1" ] && [ -d "$1" ]
then
    path="$1"
elif [ ! -z "$1" ]
then
    echo "Invalid path defined, using default."
fi
 
echo "Searching for php short open tags..."
echo "Starting path: $path"
find $path -name '*.php' -type f -exec perl -i -wpe 's/<\?=/<\?php echo /g' '{}' \; 
find $path -name '*.php' -type f -exec perl -i -wpe 's/<\?/<\?php/g' '{}' \; 
find $path -name '*.php' -type f -exec perl -i -wpe 's/<\?phpphp/<\?php/g' '{}' \; 
find $path -name '*.ctp' -type f -exec perl -i -wpe 's/<\?=/<\?php echo /g' '{}' \; 
find $path -name '*.ctp' -type f -exec perl -i -wpe 's/<\?/<\?php/g' '{}' \; 
find $path -name '*.ctp' -type f -exec perl -i -wpe 's/<\?phpphp/<\?php/g' '{}' \; 
find $path -name '*.inc' -type f -exec perl -i -wpe 's/<\?=/<\?php echo /g' '{}' \; 
find $path -name '*.inc' -type f -exec perl -i -wpe 's/<\?/<\?php/g' '{}' \; 
find $path -name '*.inc' -type f -exec perl -i -wpe 's/<\?phpphp/<\?php/g' '{}' \; 
find $path -name '*.thtml' -type f -exec perl -i -wpe 's/<\?=/<\?php echo /g' '{}' \; 
find $path -name '*.thtml' -type f -exec perl -i -wpe 's/<\?/<\?php/g' '{}' \; 
find $path -name '*.thtml' -type f -exec perl -i -wpe 's/<\?phpphp/<\?php/g' '{}' \; 
 
echo 'Done!'

Please leave the credits in if you want to modify it.
Donations are welcome haha :-P

Comments (1) Trackbacks (0)
  1. This worked great! Thanks!


Leave a comment


No trackbacks yet.