Here are 30 examples of PHP commands with their usage:
php -v
: Displays the current version of PHP installed on the system.php -m
: Lists all PHP modules installed on the system.php -r "echo 'Hello World';"
: Runs a PHP script on the command line that prints “Hello World”.php -i
: Displays the PHP configuration information.php -a
: Opens an interactive shell for executing PHP commands.php -f filename.php
: Executes a PHP script file.php -S localhost:8000
: Starts a simple PHP web server on port 8000.php -l filename.php
: Checks the syntax of a PHP script file.php -c custom.ini filename.php
: Executes a PHP script with a custom configuration file.php -d display_errors=1 filename.php
: Sets a PHP configuration directive for a script execution.php -r "echo PHP_EOL;"
: Prints a newline character on the command line.php -a -d readline.prompt='> '
: Starts an interactive shell with a custom prompt.php -r "var_dump(get_loaded_extensions());"
: Prints an array of all loaded PHP extensions.php -r "echo ini_get('memory_limit');"
: Prints the current PHP memory limit.php -r "echo getcwd();"
: Prints the current working directory.php -r "echo implode(',', range(1,10));"
: Prints a comma-separated list of numbers from 1 to 10.php -r "echo strtoupper('hello world');"
: Prints “HELLO WORLD” on the command line.php -r "echo base64_encode('hello world');"
: Encodes the string “hello world” in base64.php -r "echo file_get_contents('http://example.com');"
: Retrieves the contents of a remote URL.php -r "echo time();"
: Prints the current Unix timestamp.php -r "echo date('Y-m-d H:i:s');"
: Prints the current date and time in the specified format.php -r "echo md5('hello world');"
: Calculates the MD5 hash of the string “hello world”.php -r "echo strlen('hello world');"
: Prints the length of the string “hello world”.php -r "echo str_replace('world', 'PHP', 'hello world');"
: Replaces the word “world” with “PHP” in the string “hello world”.php -r "echo preg_replace('/\d+/', '#', '1 2 3 4 5');"
: Replaces all digits in the string “1 2 3 4 5” with the “#” character.php -r "echo serialize(['hello', 'world']);"
: Serializes an array into a string.php -r "echo json_encode(['hello' => 'world']);"
: Encodes an associative array into a JSON string.php -r "echo implode(PHP_EOL, ['hello', 'world']);"
: Prints “hello” and “world” on separate lines.php -r "echo hash('sha256', 'hello world');"
: Calculates the SHA-256 hash of the string “hello world”.php -r "echo bin2hex(random_bytes(16));"
: Generates a random string of 16 bytes and prints
Latest posts by Rajesh Kumar (see all)
- Best AI tools for Software Engineers - November 4, 2024
- Installing Jupyter: Get up and running on your computer - November 2, 2024
- An Introduction of SymOps by SymOps.com - October 30, 2024