Page 1 of 1

XAMPP 1.8 PHP problem? [Solved]

PostPosted: 15. August 2012 06:42
by Ragnarok210
Hello,
I got this problem in XAMPP 1.8 where php is not show correctly in browser. Apparently, there are couple of people who had this problem as I read other posts. As I did some test myself, I found out that it only happened in the new XAMPP 1.8, thought I am not sure whether it's the PHP 5.4 problem or XAMPP itself.

Here is the script that i tested it with, index.php and LIB.php.
index.php ========================================
Code: Select all
<?php
   require_once 'LIB.php';
   $string = html_header($title="Home",$style = "styles_sheet.css");
   $string .= "<h1>HELLO</h1>";
   $string .= html_footer();
   echo $string;   
?>

LIB.php ========================
Code: Select all
<?
   function html_header($title="Untitled",$styles = "styles_sheet.css"){
      $string =<<<HEAD
      <!DOCTYPE html>
      <html xmlns = "http://www.w3.org/1999/xhtml">
      <head>
         <meta http-equiv = "content-type" content="text/html;charset=utf-8" />
         <title>$title</title>
         <link type = "text/css" rel= "stylesheet" href = "$styles" />
      </head>
      <body>
HEAD;
      return $string;
   }
   function html_footer(){
      $string =<<<FOOT
         </body>
         </html>
FOOT;
      return $string;
   }
?>

==================================================

In XAMPP 1.7.7, it works fine... which's it shows "Hello" in h1 tag.
in XAMPP 1.8.0, here is the result...
Image

When you run even simpler code such as <?php echo "hello"; ?> it work fine, phpInfo() work fine too..

note: I tried reinstalling, didn't work either. I view the file through server localhost, and not directly on computer. I did install the microsoft c++ 2008 32bit.

Any help would be appreciated, Thanks in Advance...

[EDIT by Altrea: added code-BBTags around code. Please next time add them on your own.]

Re: XAMPP 1.8 PHP problem?

PostPosted: 15. August 2012 09:45
by adi06
What do u mean by :
I got this problem in XAMPP 1.8 where php is not show correctly in browser.

What is not showing correctly?
And ur provided pic is not here anymore...

Re: XAMPP 1.8 PHP problem?

PostPosted: 15. August 2012 15:21
by JonB
Is it possible you have short_open_tag off? :shock:

Good Luck
8)

Re: XAMPP 1.8 PHP problem?

PostPosted: 15. August 2012 16:40
by Ragnarok210
The picture there is showing the problem (the picture is still there O.O) displaying the php page in XAMPP 1.8.0.
@adi06 I mention the script work in XAMPP 1.7.7. Which is showing <h1>Hello</h1> in browser. It works fine in XAMPP 1.7.7, which's php version 5.3.8 I believe.
Both used the same script.

@JonB I triple checked, there's no short_open_tag or any syntax error.
Ignoring that LIB.php script there. If you replace it with ----->
Code: Select all
<? php
function html_header(){
            echo "This is in LIB.php";
}
function html_footer(){
            echo "Hello from footer";
}

It doesn't work either.

note: What I use originally was the Heredoc syntax, I thought that was causing the problem. Apparently it's not.
Thanks for responding...

Re: XAMPP 1.8 PHP problem?

PostPosted: 15. August 2012 16:56
by JonB
when you run this code - what is the output?

Code: Select all
<? php
function html_header(){
            echo "This is in LIB.php";
}
function html_footer(){
            echo "Hello from footer";
}


8)

Re: XAMPP 1.8 PHP problem?

PostPosted: 15. August 2012 17:52
by Altrea
Seems to me like your HEREDOC string blocks are not terminated correctly.
Do you have any invisible whitespaces in front of your HEAD; line?

Re: XAMPP 1.8 PHP problem?

PostPosted: 15. August 2012 17:57
by Altrea
Forget what i said before. Of cause JonB is correct.
short_open_tags are setted to Off by default in the current version 8)

Ragnarok210 wrote:Ignoring that LIB.php script there. If you replace it with ----->
Code: Select all
<? php
function html_header(){
            echo "This is in LIB.php";
}
function html_footer(){
            echo "Hello from footer";
}

It doesn't work either.


There is a space between <? and php. Sure, this will not work, because it is still a short open tag.

Re: XAMPP 1.8 PHP problem?

PostPosted: 15. August 2012 18:40
by Ragnarok210
Ah I just figure it out as I type this. Apparently, php document still works in 5.3.8 if you leave out the <? (php), but not in 5.4.

Thanks for the help...

Re: XAMPP 1.8 PHP problem?

PostPosted: 15. August 2012 18:54
by JonB
ah yes - that would be SHORT OPEN TAG :shock:

its a setting in php.ini edited (that will now not work quite the same way)

8)

Re: XAMPP 1.8 PHP problem?

PostPosted: 15. August 2012 19:17
by Ragnarok210
Yea, I guess you were right, funny thing is now I checked the short_open_tag, the default was On O.o?, So I turn both development value and production value to On (even thought i am not sure what they do), then restart the apache server. It still doesn't work with <?, but whatever I am satisfy, doesn't hurt adding extra 3 letters.

Thanks again...

Re: XAMPP 1.8 PHP problem?

PostPosted: 15. August 2012 20:50
by JonB
That is because of a change - to clarify/avoid problems with xml -

http://stackoverflow.com/questions/8004 ... g-open-tag

Good explanation:

http://programmers.stackexchange.com/qu ... tag-in-php

Good Luck

Re: XAMPP 1.8 PHP problem?

PostPosted: 16. August 2012 03:40
by Altrea
Ragnarok210 wrote:funny thing is now I checked the short_open_tag, the default was On O.o?, So I turn both development value and production value to On

funny thing, you don't changed the setting. What you have changed are just comments what settings are common for some environments. This are just examples.
The real setting don't have a semicolon in front of the line.

best wishes,
Altrea