Jump to content


Photo

Problem with <? vs. <?php


  • Please log in to reply
7 replies to this topic

#1 webkidd

webkidd
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 19 October 2006 - 07:30 PM

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

#2 sanfly

sanfly
  • Members
  • PipPipPip
  • Advanced Member
  • 344 posts
  • LocationNew Zealand

Posted 19 October 2006 - 07:38 PM

Do you have access to the php.ini file?

http://php.net/ini.core
If you're not part of the solution, you're part of the precipitate

#3 BrandonK

BrandonK
  • Members
  • PipPip
  • Member
  • 27 posts

Posted 19 October 2006 - 07:41 PM

<? ?> is using short tags which can be disabled by default in newer versions of PHP.

#4 webkidd

webkidd
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 19 October 2006 - 08:57 PM

Yes I can edit the php.ini.

How do I turn it back on?

#5 sanfly

sanfly
  • Members
  • PipPipPip
  • Advanced Member
  • 344 posts
  • LocationNew Zealand

Posted 19 October 2006 - 09:27 PM

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?
If you're not part of the solution, you're part of the precipitate

#6 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 19 October 2006 - 09:28 PM

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.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#7 Jenk

Jenk
  • Members
  • PipPipPip
  • Advanced Member
  • 778 posts

Posted 19 October 2006 - 11:13 PM

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:

<?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');

?>

untested

#8 webkidd

webkidd
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 20 October 2006 - 07:44 PM

Thanks.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users