Question

I have a problem with my local server ( WampServer ) . I am trying to run my website but some of the pages displayed incorrectly . This is an example : The browser (firefox version 26) displays the following

Sin noticias

'; } else { foreach( $news as $new ) { echo '
' . date_helper::timestamp_to_string( $new->date ) .'
       ' . $new->text .'
'; } } ?>

I'm using the Kohana framework version 2.3.4 . The apache version is: 2.2.22 , PHP version: 5.4.3 and mysql 5.5.24 . The code of the page I want to show is the following :

<?php defined('SYSPATH') OR die('No direct access allowed.'); ?>
<div class="general-content">

<? if( count( $news ) == 0 ) {
    echo '<p>Sin noticias</p>';
}
else
{
    foreach( $news as $new )
    {
        echo '<p style="margin-bottom:20px"><span class="newsdate">'
             .  date_helper::timestamp_to_string( $new->date )
             .'</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
             .  $new->text
             .'</p>';
    }
}
?>
<script>
// Load the classic theme
Galleria.loadTheme('/data/galleria/themes/classic/galleria.classic.min.js');
// Initialize Galleria
Galleria.run('#galleria');
Galleria.run('#galleria2');
</script>
<br/>
<p><center><?= $pagination ?></center></p>
</div>

<? common::print_return_to_main_page() ?>

Is it a problem with php or apache ?

Was it helpful?

Solution

it's because your short tag isn't recognized here:

<? if( count( $news ) == 0 ) {
   echo '<p>Sin noticias</p>';
}
//...

Should be:

<?php if( count( $news ) == 0 ) {
   echo '<p>Sin noticias</p>';
}
//....

That PHP is not seen as such and therefore not parsed, and the browser sees <? as a start tag which is ended by the </p> after "noticias". That's why you get your actual result on the page.

The reason of this is because you likely have short_open_tag directive disabled in your php.ini. Keep in mind that :

Since PHP 5.4.0, <?= is always available

which is the short for <?php echo, but that doesn't encompass the <? short tag in lieu of <?php

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top