w3resource

PHP Exercises : Print current PHP version

PHP : Exercise-17 with Solution

Write a PHP script to print current PHP version.

Note : Do not use phpinfo() function.

Sample Solution: -

PHP Code:

<?php
echo 'Current PHP version : ' . phpversion();
  // prints e.g. '2.0' or nothing if the extension isn't enabled
  echo phpversion('tidy')."\n";
?>

Sample Output:

Current PHP version : 7.0.15-0ubuntu0.16.04.4 

Flowchart:

Flowchart: Print current PHP version

Note: string phpversion (string $extension ): Returns a string containing the version of the currently running PHP parser or extension.

PHP Release History:

Version Release date Supported until
1.0 8 June 1995
2.0 1 November 1997
3.0 6 June 1998 20 October 2000
4.0 22 May 2000 23 June 2001
4.1 10 December 2001 12 March 2002
4.2 22 April 2002 6 September 2002
4.3 27 December 2002 31 March 2005
4.4 11 July 2005 7 August 2008
5.0 13 July 2004 5 September 2005
5.1 24 November 2005 24 August 2006
5.2 2 November 2006 6 January 2011
5.3 30 June 2009 14 August 2014
5.4 1 March 2012 3 September 2015
5.5 20 June 2013 10 July 2016
5.6 28 August 2014 31 December 2018
6.x Not released N/A
7.0 3 December 2015 3 December 2018
7.1 1 December 2016 1 December 2019
7.2 30 November 2017 30 November 2020

Beginning on June 28, 2011, the PHP Group implemented a timeline for the release of new versions of PHP. Under this system, at least one release should occur every month. More details: http://php.net/releases/

PHP Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a PHP script to count number of lines in a file.
Next: Write a PHP script to delay the program execution for the given number of seconds.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



PHP: Tips of the Day

Why shouldn't I use mysql_* functions in PHP?

The MySQL extension:

  • Is not under active development
  • Is officially deprecated as of PHP 5.5 (released June 2013).
  • Has been removed entirely as of PHP 7.0 (released December 2015)
  • This means that as of 31 Dec 2018 it does not exist in any supported version of PHP. If you are using a version of PHP which supports it, you are using a version which doesn't get security problems fixed.
  • Lacks an OO interface
  • Doesn't support:
    • Non-blocking, asynchronous queries
    • Prepared statements or parameterized queries
    • Stored procedures
    • Multiple Statements
    • Transactions
    • The "new" password authentication method (on by default in MySQL 5.6; required in 5.7)
    • Any of the new functionality in MySQL 5.1 or later

Since it is deprecated, using it makes your code less future proof.

Lack of support for prepared statements is particularly important as they provide a clearer, less error-prone method of escaping and quoting external data than manually escaping it with a separate function call.

Ref : https://bit.ly/2BIIsF0