Does the shebang line work with php?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Ixplodestuff8
Forum Commoner
Posts: 60
Joined: Mon Feb 09, 2004 8:17 pm
Location: Queens, New York

Does the shebang line work with php?

Post by Ixplodestuff8 »

if I had a script like this:

Code: Select all

#!/usr/bin/php
<?php
//code
?>
and access the file directly would it run correctly?
Coco
Forum Contributor
Posts: 339
Joined: Sat Sep 07, 2002 5:28 am
Location: Leeds, UK
Contact:

Post by Coco »

not wanting to seem rude, but in my opinion, the easiest way to learn has always been to try it myself :)

try running file something like this:

Code: Select all

#!/usr/bin/php 
<?php 
echo 'it works!';


?>
User avatar
Ixplodestuff8
Forum Commoner
Posts: 60
Joined: Mon Feb 09, 2004 8:17 pm
Location: Queens, New York

Post by Ixplodestuff8 »

Yeah trying it out myself is the best way, but since It was late, I just posted the question to see if it was answered the next day, so I didn't have to test it out myself. (lazyness ;) )

And BTW it does work 8) , of course it does have the php headers in it, but those can be turned off in the php.config, and the script I'm writing doesn't have any output so I can just direct output to /dev/null.
dave420
Forum Contributor
Posts: 106
Joined: Tue Feb 17, 2004 8:03 am

Post by dave420 »

Just add -q to the /usr/bin/php, and it'll turn off the headers. This works fine for linux and mac OSX, and with a .bat companion for windows, can let you make portable scripts which work on macs, windows and linux (I wrote a few for my ipod, and it's all portable (in every sense of the word) :))
Post Reply