For others, KoolKabin is referring to the use of <?
instead of <?php
as the opening tag for php code, usually used in this abbreviated form:
<?= $myvar1, $myvar2 ?>
Which is equivalent to this:
<? echo $myvar1, $myvar2 ?>
Which is itself equivalent to this, when the server is so configured with short_open_tag = on in php.ini:
<?php echo $myvar1, $myvar2 ?>
Personally, I’d convert all the short tags unless there are many pages that have nothing but short tags.
Writing some code around token_get_all() is your safest bet (as I detail in a separate answer here), but you might be able to get away with a simple sed script:
sed -e 's/<?\([ \t\r]\)/<?php\1/g' \
-e 's/<?$/<?php/g' \
-e 's/<?=\([ \t\r]\)\?/<?php echo \1/g'
Just beware of strings in your code (regexes, particularly) that might have the <?
sequence followed by a whitespace character. See also: Useful one-line scripts for sed, where it’s pointed out that sed syntax varies, and that some don’t support the \t
code (but you can type in an actual tab character).
n.b. Beware that sed doesn’t use Perl regexes and at least one of the other replies here has invalid sed syntax: e.g. \?
in Perl is a literal question mark, but he intends ?
, which is a literal question mark in sed. (He also replaces <?=
with <?php
, incorrectly omitting the “echo”.)