Last Updated: February 25, 2016
·
938
· augustohp

Fix PHP short_open_tags (<?)

This shell script changes all PHP short open tags (<?) in a directory (recursive) to the complete PHP open tag (<?php). Tested only on OSX 10.6 (bash 3.2.48), be sure to check the current state of your working copy code before running this.

# Gets all the files that has PHP short_open_tags 
# in the currently directory (recursively)
for filename in `grep -r '<? ' . | grep -v '.git' | cut -d : -f 1 | sort | uniq` then
    # Changes all short_open_tags in the file to <?php
    sed 's/<\? /<\?php /g' $filename > /tmp/a && mv /tmp/a $filename
done

Original gist: https://gist.github.com/2407874

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Related Tags
#php
#bash
Did you know?

PHP applications still send a browser full of JavaScript. Hardening the server does not inventory the payment, analytics, and plugin scripts that run after the HTML is delivered.

Security insights from Cside