Skip to content

Instantly share code, notes, and snippets.

@iCodeForBananas
Created September 26, 2014 20:23
Show Gist options
  • Save iCodeForBananas/ee4eb695b26f2e927d59 to your computer and use it in GitHub Desktop.
Save iCodeForBananas/ee4eb695b26f2e927d59 to your computer and use it in GitHub Desktop.
#!php-cli
<?php
$path = realpath('public');
$objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST);
foreach($objects as $name => $object)
{
$path_parts = pathinfo($name);
if (! isset($path_parts['extension']) OR $path_parts['extension'] !== 'php')
{
continue;
}
$initial_file_contents = file_get_contents($name);
$replaced_file_contents = preg_replace(
array(
"/<\?=([^\?]+)\?>/s",
"/<\?[^p]/s"
),
array(
"<?php echo $1; ?>",
"<?php\n"
),
$initial_file_contents);
if (strcmp($initial_file_contents, $replaced_file_contents) != 0)
{
file_put_contents($name, $replaced_file_contents);
echo "Converted: {$name}\n";
}
}
<?
$var = 'test';
echo $var;
?>
<?=$test?>
<?= $test ?>
<? $newVar = 'lol'; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment