Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Executing scripts in just <? 1

Status
Not open for further replies.

csteinhilber

Programmer
Aug 2, 2002
1,291
US
I have a lot of legacy scripts that were originally coded in what I suppose could be termed "shorthand"... like:
Code:
<?
   // phpscript here
?>
or
Code:
<?= $outputSomeVar ?>

rather than the more succinct
Code:
<?PHP
   // phpscript here
?>
and
Code:
<?PHP echo($outputSomeVar) ?>

They worked just fine on our Apache/PHP installs for years.

I've since switched development machines, and used WAMP (for the first time) to install my dev servers, rather than doing it all manually. Which was terrific... except now none of the shorthand code works anymore. Script blocks only work if they're in <?PHP.

First, how do I reconfig my dev server to interpret blocks with just the <? shabang.

And second, is there a reason why WAMP wouldn't already be configured to do this? I mean... beyond it being best practice to always use the PHP nomenclature. Any security issues or anything else that would make it worth the effort to convert all our existing scripts to abide by these practices?


-Carl
 
open php.ini
add this line if it is not there:
Code:
short_open_tag = On

if it is there then make sure that it is uncommented and set to "On"

save and close the file

if you are using php as a sapi module, you will need to restart your web server.

if you are using php as a cgi in a hosted and shared environment, you may be able to load just a local php.ini into the folder in which your script resides





 
Thank you, jpadie! That worked like a charm.

Trying to find it on my own was driving me a little nuts (you try to Google "<?" ;) )

Anyway... is there any reason why one would need/want to keep short_open_tag = Off? Is it best practice to enforce the use of... well... long_open_tags? Or is the option there simply to help make sure PHP doesn't step on scripts in other languages, etc?

Thanks again!



-Carl
 
i believe it's the latter. in particular the combination of xml and php would create a hiccup with short open tags. consider running

Code:
<? xml version...
through a php parser...

there may be other languages that create a conflict too.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top