Saturday, February 7, 2009

Accessing command line from PHP code

It is sometimes necessary (or easier) to execute command line commands from within PHP code, in this post I will show an example of such usage. If you only need an über-basic example, here it is:

<?php

$thisf = $_SERVER['SCRIPT_NAME'];
`cp
$thisf newname.php`;

?>


This little piece of code will copy the running script to newfile.php. If you're not satisfied yet, keep reading.