php5 command line

Ryan Schmidt ryandesign at macports.org
Wed Dec 5 01:37:28 PST 2007


On Dec 5, 2007, at 03:15, Michael Thon wrote:

> On Dec 5, 2007, at 8:01 AM, Ryan Schmidt wrote:
>
>> On Dec 4, 2007, at 23:49, Michael Thon wrote:
>>
>>> Greetings - I am running php5 on Mac OS 10.4 Intel.  When I  
>>> execute a php command line script, php prints the contents of the  
>>> script on the terminal rather than executing it.  If I run the  
>>> script with apple's php the script runs fine.  the same script  
>>> also runs ok on a linux box with php 5.1.  Any ideas whats going on?
>>
>> No, no idea. I use the php command line from the MacPorts php5  
>> port all the time. Never seen this.
>>
>> So, just to be clear, what happens if you put the following three- 
>> line script into a file test.php and then run it with both Apple's  
>> and MacPorts's php?
>>
>>
>> <?php
>> echo "hello php " . PHP_VERSION . "\n";
>> ?>
>>
>>
>> Here's what I get:
>>
>> $ /usr/bin/php test.php
>> hello php 4.4.7
>> $ /opt/local/bin/php test.php
>> hello php 5.2.5
>>
>>
>> If that's not what you get, then I'd like to see your php.ini.
>
> If I run your test script it works fine.  looking a little closer  
> at my student's code I see that the shebang line (or whatever you  
> call it in php is:
> <?
> when it should be:
> <?php
> Interestingly, the <? version works with /usr/bin/php and on the  
> linux box but not with the macports php5.  I did get the <? script   
> to run with this command line:
> /opt/local/bin/php -n myscript.php
> which I take to mean that there is something in the php.ini file  
> that is different from the linux and default Mac OS install.
> Anyway, my solution is to add <?php to the files.

Beginning PHP code fragments with "<?php" is the portable way to do  
it. This will work on every PHP interpreter. "<?", however, will only  
work if "short_open_tag" is set to "on" in the php.ini, and is  
therefore not recommended, since some installations may have it set  
to "off".



More information about the macports-users mailing list