โœ‚๏ธย PHP

Small information nuggets and recipies about PHP


(most recent on top)

Which url requested this file?

echo $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"];

Command line scripts

php -r '$var = value';
php -a                            # interactive (needs readline)

Show all defined constants

print_r(@get_defined_constants());

Default values for contents

defined('CONSTANT')? : define('CONSTANT', 'value');
defined('CONSTANT') || define('CONSTANT', 'value');
defined('CONSTANT') or define('CONSTANT', 'value');

Default values for variables

isset($var)? : $var = 'value';
isset($var) || $var = 'value';
isset($var) or $var = 'value';