Search code examples
phpregexserver-migration

RegExp to fix php tags


I made a website using php. In some places I put these php tags <?php ?> in other places just those <? ?>.

After doing a server migration the latter tags do not work because of php version differences. The new server understands only these tags <?php ?>.

Is there any easy regular expression that you can provide me to replace all <? some php code here ?> to <?php some php code here ?>.


Solution

  • You have two possibilities here:

    1. Enable the short tags with short_open_tag=On in php.ini
    2. You could use a negative lookahead: <\?(?!php), these needs to be replaced with <?php, see a demo on regex101.com.