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
?serializeto the url
Only want PHP 5 releases?&version=5
The last 3?&max=3Want a JSON list of the PHP releases?
Add
?jsonto 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
How do you update PHP to latest version (e.g. 7.4.21)?
Finding PHP latest release version - Stack Overflow
PHP version stats: July, 2022
Should I update from PHP 7.4 ?
Videos
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
?serializeto the url
Only want PHP 5 releases?&version=5
The last 3?&max=3Want a JSON list of the PHP releases?
Add
?jsonto 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
$data = @file_get_contents('https://www.php.net/releases/?json');
$data = @json_decode($data, true);
$data = current($data);
echo 'Latest version: ' . $data['version'];