PHP, Programming

Quick and Dirty Command Line PHP

I do 99% of my programming in PHP, and when I’m on the command line, I would rather use the PHP functions I know than look up the Bash functions I don’t, so I wrote this PHP script and saved it in my $PATH as an executable file named p.

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

var_dump(
	call_user_func_array(
		$argv[1],
		array_slice( $argv, 2 )
	)
);

This way, if I want to quickly get the length of a string, I can type:

$ p strlen paraskavedekatriaphobia

and get

int(23)

instead of looking up that I could have done:

$ foo=paraskavedekatriaphobia && echo ${#foo}

(or apparently a dozen other methods of finding the length of a string in Bash).

It even works with Bash variables:

$ foo=acbdef
$ p strlen $foo
int(6)

Thanks to all the time this script has saved me, I was able to write this post!

Standard

Leave a Reply

Your email address will not be published. Required fields are marked *