tags:

views:

38

answers:

4

I've recently inherited a website written in PHP and given the responsibility to move it from the current host to our own internal web servers.

I succesfully copied the files and i can browse the site on our webserver (IIS7) however some, not all, of the PHP scripts do not appear to execute properly.

For example, the following code loads some text content from a database and displays fine on the existing server,

<?php $sql = "select * from tblsubpages where PageID = 1 " ; $page_Result=mysql_query($sql); while ( $page_Row = mysql_fetch_array ( $page_Result)) {
?>

<?=str_replace('<blockquote>','',$page_Row['Details']); ?>

however on the new server all i get is the following output in the place where the text content should be.

','',$page_Row['Details']); ?>

The files are identical on both sites and i've verified they can both succesfull connect to the mySQL server.

Question - Any ideas where i can begin troubleshooting or what can be the cause ?

+2  A: 

It might be a problem with php.ini's short_open_tag directive on your new host. Check if it is off and if so, try switching it on.

middus
great, knew it had to be simple
Khalid Rahaman
+1  A: 

First things first.

  • Make sure you are using the same php versions

  • Copy over your php.ini file.

  • It looks like your ini file has short tags disabled. Change <?= to <?php echo

jostster
+2  A: 

In the php.ini file set :

short_open_tag = On

or change

<?=

to

<?php
piddl0r
+1  A: 

If you don't want to turn on short_tags you could try to convert them:

foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator(DIRECTORY)) as $file) {
    if (!$file->isFile()) continue;

    $tokens = token_get_all(file_get_contents($file));
    $source = '';
    foreach ($tokens as $token) {
        if (is_string($token)) {
            $source .= $token;
            continue;
        }

        if ($token[0] == T_OPEN_TAG_WITH_ECHO) {
            $token[1] = '<?php echo ';
        }
        $source .= $token[1];
    }

    file_put_contents($file, $source);
}

This iterates over the token of the source and replaces T_OPEN_TAG_WITH_ECHO by <?php echo.

nikic