PHP Commands
Server-side scripting language.All PHP pages
- php -l file.php: check a PHP file for syntax errors (lint)php -l file.php checks a PHP file for syntax errors without running it: the output, exit status 255 on errors, linting a project with find, and what it misses.
- php -r: run PHP code from the command line without a filephp -r runs PHP code from the command line without a file or <?php tag. Quoting in bash and cmd.exe, passing arguments via $argv, and related CLI options.
- php check if a string contains a substring (str_contains, strpos)Check if a string contains a substring in PHP with str_contains (PHP 8+), or strpos !== false on PHP 7. Case-insensitive checks and the strpos position 0 trap.
- php json_encode pretty print (JSON_PRETTY_PRINT and other flags)Pretty-print JSON in PHP with json_encode($data, JSON_PRETTY_PRINT), plus unescaped slashes and Unicode, JSON_THROW_ON_ERROR, and why it can return false.