Jump to content

Archived

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

webkidd

Problem with <? vs. <?php

Recommended Posts

I just started a new server. My old server had no problem if scripts had <? instead of <?php. Now my server will not parse them and the page comes up blank.

What do I need to do?

- Steve

Share this post


Link to post
Share on other sites
Do you have access to the php.ini file?

[url=http://php.net/ini.core]http://php.net/ini.core[/url]

Share this post


Link to post
Share on other sites
Firstly, always back up your php.ini file before you make any changes

Try searching for short_open_tag and see what value it is set to (0 or 1).  From the information in the link I gave you, I would assume that 0 is off and 1 is on?

Share this post


Link to post
Share on other sites
It's best to alway's just code with <?php
Look throughout each page with search and replace.
Or find and replace.
<?

with
<?php
or just do it with php itself using str_replace()
It's not good practice getting in that habit, as you can see, you will encounter problems.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

×

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.