Last Updated: February 25, 2016
·
1.919K
· mauris

PHP hashbang

You can use hashbang in PHP files on Mac/Linux systems to help you quickly build PHP scripts that can be run from terminals quickly. Sample:

File: myscript

#!/usr/bin/env php
<?php

echo 'hello world!';

To make this work for Windows, simply write an accompanying batch file:

File: myscript.bat

@echo off
php %~dp0myscript %*

Beautiful and cross-platform.