You are here: Re: [PHP] Is echo tag reasonably portable? « PHP « IT news, forums, messages
Re: [PHP] Is echo tag reasonably portable?

Posted by Robin Vickery on 11/16/05 01:27

On 11/15/05, Greg Donald <destiney@destiney.com> wrote:
> On Tue, 15 Nov 2005, Jim Moseby wrote:
>
> >> for file in *.php; do
> >> cp $file $file.tmp
> >> sed -e "s/<?$/<?php/g" $file.tmp >$file
> >> rm $file.tmp
> >> done
> >
> > I maintain: "Better to save the grief and do it right to start with, no?"
>
> Maybe at some point I too will be lucky enough to only work on code that
> I authored.
>
> for file in *.php; do
> cp $file $file.tmp
> php -r 'echo preg_replace("/<\?php=\s*/i","<?php echo
> ",preg_replace("/<\?(?!php)/i","<?php",file_get_contents($argv[1])));'
> $file.tmp >$file
> rm $file.tmp
> done

I'd be inclined to do it with the tokenizer functions with something
like this (untested):

<?php

$source = file_get_contents($argv[1]);
$token = token_get_all($source);

foreach ($token as $t) {
if (is_string($t)) {
print $t;
continue;
}

switch ($t[0]) {
case T_OPEN_TAG_WITH_ECHO:
print '<?php echo ';
break;
case T_OPEN_TAG:
print '<?php ';
break;
case T_CLOSE_TAG:
print ' ?>';
break;
default:
print $t[1];
}
}

?>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация