As you may already know, obtaining the version number of PHP is a simple
php --version away. This is great if you just want to see the version number, but what if you wanted just the version number? First option would be to use write out some shell script to snag just the version number:
That line will pipe the blog of PHP version information to
head which we tell to only give us the first line (the one with the version number in it) and then pipes it to
awk to print out the second word (which is the version number). It gets the job done but if you wanted, you could accomplish the same by leveraging PHP’s CLI interface:
Definitely not as much going on in the PHP-only solution but it gets it done. I did do some rudimentary speed tests and both solutions performed in about the same amount of time.