Back ticks in PHP¶
Here’s a fun little PHP fact, Did you know, text enclosed within back ticks ( ` ) is executed within the shell command line?
Fetch the user Apache runs under¶
This ones quite useful when setting directory permissions and you don’t know which user your web-server is running as. The example below uses the default Apache server as provided by Mac OS X 10.9.
// Returns the current user apache executed the script as print_r(`whoami`); # Outputs: `_www`
Get the directory of the current running script¶
// directory of the running script (index.php in the `web` directory) print_r(`pwd`); // Outputs: `/Users/Anil/Sites/website/web/`
You can use the nl2br function of PHP to output a better formatted version.