Skip to content

Instantly share code, notes, and snippets.

@adamculp
Forked from ma2thieu/replace_php_short_tags.sh
Last active February 24, 2023 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamculp/f85d1200e1b557cfc15eec40328f7136 to your computer and use it in GitHub Desktop.
Save adamculp/f85d1200e1b557cfc15eec40328f7136 to your computer and use it in GitHub Desktop.
replace php short tags (<?) with long one (<?php)
#!/bin/bash
# purpose of these lines are to change short PHP tags to the full "<?php" style tag version
# PHP version 7+ has deprecated short tags
# first short PHP tags with something that is not a letter after
find . -iname "*.php" -print0 | xargs -0 -I{} sed -i -r 's/(<\?)([^a-zA-Z])/\1php\2/g' '{}'
# then find short PHP tags at end of line
find . -iname "*.php" -print0 | xargs -0 -I{} sed -i -r 's/<\?$/<\?php/g' '{}'
# IMPORTANT: On OSX you should add the -E flag to sed so extended regular expression is used.
@jaydouble
Copy link

With
find . -iname "*.php" -print0 | xargs -0 -I{} sed -i -r 's/(<\?)([^a-zA-Z=]|$)/\1php\2/g' '{}'
you replace also the <?\n

@kyrare
Copy link

kyrare commented Feb 24, 2023

This code replace <?=LANGUAGE_ID;?> to <?php=LANGUAGE_ID;?>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment