{"id":33701,"date":"2023-05-03T02:51:09","date_gmt":"2023-05-03T02:51:09","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=33701"},"modified":"2023-05-03T02:51:10","modified_gmt":"2023-05-03T02:51:10","slug":"php-tutorials-list-of-30-example-with-its-usage-of-php-command","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/php-tutorials-list-of-30-example-with-its-usage-of-php-command\/","title":{"rendered":"PHP Tutorials: List of 30 example with its usage of php command"},"content":{"rendered":"\n<p>Here are 30 examples of PHP commands with their usage:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><code>php -v<\/code>: Displays the current version of PHP installed on the system.<\/li>\n\n\n\n<li><code>php -m<\/code>: Lists all PHP modules installed on the system.<\/li>\n\n\n\n<li><code>php -r \"echo 'Hello World';\"<\/code>: Runs a PHP script on the command line that prints &#8220;Hello World&#8221;.<\/li>\n\n\n\n<li><code>php -i<\/code>: Displays the PHP configuration information.<\/li>\n\n\n\n<li><code>php -a<\/code>: Opens an interactive shell for executing PHP commands.<\/li>\n\n\n\n<li><code>php -f filename.php<\/code>: Executes a PHP script file.<\/li>\n\n\n\n<li><code>php -S localhost:8000<\/code>: Starts a simple PHP web server on port 8000.<\/li>\n\n\n\n<li><code>php -l filename.php<\/code>: Checks the syntax of a PHP script file.<\/li>\n\n\n\n<li><code>php -c custom.ini filename.php<\/code>: Executes a PHP script with a custom configuration file.<\/li>\n\n\n\n<li><code>php -d display_errors=1 filename.php<\/code>: Sets a PHP configuration directive for a script execution.<\/li>\n\n\n\n<li><code>php -r \"echo PHP_EOL;\"<\/code>: Prints a newline character on the command line.<\/li>\n\n\n\n<li><code>php -a -d readline.prompt='&gt; '<\/code>: Starts an interactive shell with a custom prompt.<\/li>\n\n\n\n<li><code>php -r \"var_dump(get_loaded_extensions());\"<\/code>: Prints an array of all loaded PHP extensions.<\/li>\n\n\n\n<li><code>php -r \"echo ini_get('memory_limit');\"<\/code>: Prints the current PHP memory limit.<\/li>\n\n\n\n<li><code>php -r \"echo getcwd();\"<\/code>: Prints the current working directory.<\/li>\n\n\n\n<li><code>php -r \"echo implode(',', range(1,10));\"<\/code>: Prints a comma-separated list of numbers from 1 to 10.<\/li>\n\n\n\n<li><code>php -r \"echo strtoupper('hello world');\"<\/code>: Prints &#8220;HELLO WORLD&#8221; on the command line.<\/li>\n\n\n\n<li><code>php -r \"echo base64_encode('hello world');\"<\/code>: Encodes the string &#8220;hello world&#8221; in base64.<\/li>\n\n\n\n<li><code>php -r \"echo file_get_contents('http:\/\/example.com');\"<\/code>: Retrieves the contents of a remote URL.<\/li>\n\n\n\n<li><code>php -r \"echo time();\"<\/code>: Prints the current Unix timestamp.<\/li>\n\n\n\n<li><code>php -r \"echo date('Y-m-d H:i:s');\"<\/code>: Prints the current date and time in the specified format.<\/li>\n\n\n\n<li><code>php -r \"echo md5('hello world');\"<\/code>: Calculates the MD5 hash of the string &#8220;hello world&#8221;.<\/li>\n\n\n\n<li><code>php -r \"echo strlen('hello world');\"<\/code>: Prints the length of the string &#8220;hello world&#8221;.<\/li>\n\n\n\n<li><code>php -r \"echo str_replace('world', 'PHP', 'hello world');\"<\/code>: Replaces the word &#8220;world&#8221; with &#8220;PHP&#8221; in the string &#8220;hello world&#8221;.<\/li>\n\n\n\n<li><code>php -r \"echo preg_replace('\/\\d+\/', '#', '1 2 3 4 5');\"<\/code>: Replaces all digits in the string &#8220;1 2 3 4 5&#8221; with the &#8220;#&#8221; character.<\/li>\n\n\n\n<li><code>php -r \"echo serialize(['hello', 'world']);\"<\/code>: Serializes an array into a string.<\/li>\n\n\n\n<li><code>php -r \"echo json_encode(['hello' =&gt; 'world']);\"<\/code>: Encodes an associative array into a JSON string.<\/li>\n\n\n\n<li><code>php -r \"echo implode(PHP_EOL, ['hello', 'world']);\"<\/code>: Prints &#8220;hello&#8221; and &#8220;world&#8221; on separate lines.<\/li>\n\n\n\n<li><code>php -r \"echo hash('sha256', 'hello world');\"<\/code>: Calculates the SHA-256 hash of the string &#8220;hello world&#8221;.<\/li>\n\n\n\n<li><code>php -r \"echo bin2hex(random_bytes(16));\"<\/code>: Generates a random string of 16 bytes and prints<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>Here are 30 examples of PHP commands with their usage:<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[2],"tags":[],"class_list":["post-33701","post","type-post","status-publish","format-standard","hentry","category-uncategorised"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/33701","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=33701"}],"version-history":[{"count":1,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/33701\/revisions"}],"predecessor-version":[{"id":33702,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/33701\/revisions\/33702"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=33701"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=33701"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=33701"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}