Jump to content

Problem with <? vs. <?php


webkidd

Recommended Posts

Easier and future proof:

open the file in notepad:
ctrl+h

replace <?
with <?php

ctrl+h

replace: phpphp
with: php

If it's loads of files.. won't be hard to write a small replace script:

[code]<?php

function replaceTags($dir, $ext)
{
    if (!$dir = realpath($dir)) return false;

    $hand = opendir($dir);

    while(($item = readdir($hand)) !== false)
    {
        $path = realpath($dir . DIRECTORY_SEPARATOR . $item);
        if (!in_array($item, array('.', '..')))
        {
            if (!is_readable($path)) continue;

            if (is_dir($path))
            {
                replaceTags($path, $ext);
            }
            elseif (strtolower(substr($path, -strlen($ext))) == strtolower($ext))
            {
                $content = file_get_contents($content);
                $content = preg_replace(
                          array('/<?\s{1}/', '/<?=/'),
                          array('<?php ', '<?php echo '),
                          $content
                );
                file_put_contents($path, $content);
            }
        }
    }
    closedir($hand);
}

replaceTags('/var/www/doc_root', '.php');

?>[/code]

untested
Link to comment
https://forums.phpfreaks.com/topic/24474-problem-with/#findComment-111599
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.