1

I have a huge PHP project consisting of many PHP files, most of them opening with <?. Now I'm trying to run this in PHP5.4, so I need to convert all of these to <?php.

Hence my question;

How do I convert all opening tags from <? to <?php ?

I use JetBrains PhpStorm 7.0.

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
casparjespersen
  • 3,460
  • 5
  • 38
  • 63
  • Search and replace all `` with ` – elclanrs Jan 20 '14 at 22:44
  • 2
    @elclanrs: wrong. Search and replace all ` ` or `\n`, not `` or you will end with bunch of ` – Marcin Orlowski Jan 20 '14 at 22:47
  • @MarcinOrlowski: Not sure why make the distinction, in Vim I'd just do `s// – elclanrs Jan 20 '14 at 22:50
  • You can search in PhpStorm with this regular expression: `^\<\?$` – Marco Antonio Dec 01 '14 at 09:36
  • 3
    In PHPStorm, right click on the project source root directory. Click ***Replace In path***. Select only ***Regular Expression***, Set Context to: ***except comments and string literals*** set File masks to `*.php` (or your project's PHP extension(s)) Text to Find: `<\?=\s?` Replace: ` – Will B. Mar 28 '16 at 14:29
  • The answer above from fyrye will doe the trick. Do a search and replace for `<\?(\s|\n)` (expression) and replace with ` – Timo002 Sep 21 '16 at 19:29
  • On VSCode replace `<\?$` to php – Fury Jun 20 '19 at 14:16
  • Voting Reopen as the answer to which points this "duplicate" does not address OP's problem exactly. OP is asking how to fix the tags *in PhpStorm*, not in general – Déjà vu Mar 22 '21 at 07:03

2 Answers2

2

Try this if on Linux, you have access to a nice sed

find . -name '*.php' -exec sed -i '1s/<?$/<\?php/' {} \; -exec echo Fixing {} \;
waTeim
  • 9,095
  • 2
  • 37
  • 40
0

Problem could be solved according to comments. However, I chose to update php.ini to accept short open tags instead.

casparjespersen
  • 3,460
  • 5
  • 38
  • 63