Last Updated: February 25, 2016
·
2.178K
· 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.

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

PHP applications still send a browser full of JavaScript. Hardening the server does not inventory the payment, analytics, and plugin scripts that run after the HTML is delivered.

Security insights from Cside