Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding PHP latest release version

Tags:

php

I would like to be able to display in the application if it's running latest PHP version by comparing return of phpversion() with the latest from http://php.net/ChangeLog-5.php - can I check this in a better way than parsing the mentioned URL's HTML?

like image 571
kuba Avatar asked Aug 21 '15 09:08

kuba


1 Answers

Updated Answer

When visiting http://www.php.net/releases, I noticed that on the right panel, it says:

Want a PHP serialized list of the PHP releases?

Add ?serialize to the url
Only want PHP 5 releases? &version=5
The last 3? &max=3

Want a JSON list of the PHP releases?

Add ?json to the url
Only want PHP 5 releases? &version=5
The last 3? &max=3

So whether you'd rather use a PHP serialized version or JSON, you might use http://www.php.net/releases?serialize or http://www.php.net/releases?json

If you want to only see Version 5.x.x, you could use:

http://www.php.net/releases?json&version=5 (If you'd like to use JSON, otherwise replace json with serialize)

Original Answer (Critical, see Nannes comment)

Parsing the HTML structure is of course a bad idea, since the structure of the tags could change when a new homepage of php.net is introduced.

While searching for a solution, I came across this Atom feed: http://php.net/releases/feed.php

Since this is a Atom feed, the strucutre will not change, as it is defined by a standard 1]. You can then use PHP's default XML functions 2] to parse feed > entry:first-child > php:version (CSS-Syntax for demonstration purpose. :first-child is the first child selector, > the direct child selector) and then use PHP's version_compare 3].

More information:

  • 1] Atom standard (RFC 4287)
  • 2] PHP XML functions
  • 3] version_compare
like image 114
CharlyDelta Avatar answered Sep 22 '22 15:09

CharlyDelta