Friday, April 27, 2007

test.php: There's long tags and then there's short tags.

This problem didn't take more than a few minutes to rectify and I'm thankful for that.

My test.php file consisted of the following code:
<? echo phpinfo() ?>
This is supposed to give you a volley of information about the PHP you just installed. Unfortunately when I tried to look at the file on localhost (http://localhost/test.php) it produced a blank window. I'm scratching my head thinking what did I do wrong?

After using Google (I can't say the term "googling" for fear that I'll mess with the giant's trademark. It's not good to say you "googled" something or "Xeroxed" a paper. They might lose money *rolls eyes* But seriously I like Google so I'll use the term "using Google" or "searching on Google") to search for
"GET /test.php HTTP/1.1" 200 20" "<? echo phpinfo() ?> "
I came up with only 6 hits that didn't answer the question as to why nothing was showing up. Then it hit me. Short tags.

The php.ini file has a variable that turns "short tags" on and off. Short tags are when you use . The ini file says it best:
; Allow the tags are recognized.
; NOTE: Using short tags should be avoided when developing applications or
; libraries that are meant for redistribution, or deployment on PHP
; servers which are not under your control, because short tags may not
; be supported on the target server. For portable, redistributable code,
; be sure not to use short tags.
short_open_tag = Off
"short_open_tag" is the variable that is set to Off my default.
So all I had to do was replace <? with <?php and...
Voila!

No comments: