PHP-Shorttags ersetzen

Ich bin vor kurzem auf ein PHP-Projekt gestoßen, das Shorttags voraussetzt.
Da diese aber nicht empfohlen werden, habe ich mir mal ein Bash-Script gebastelt um die alle zu ersetzen.

[bash highlight=”7″]#!/bin/bash
if [ "$1" = "-h" ]; then
echo "Replaces short php open tags <? with <?php in all files of the current dir."
exit 0
fi

find ./ -name "*.php" -exec sed -i -e ‘s!<?php!#php_long_tag#!g’ -e ‘s!<?!#php_long_tag#!g’ -e ‘s!#php_long_tag#!<?php !g’ {} \;

echo "done"

exit 0[/bash]

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.