Skip to content

Instantly share code, notes, and snippets.

View stevenrombauts's full-sized avatar
:shipit:

Steven Rombauts stevenrombauts

:shipit:
View GitHub Profile
@stevenrombauts
stevenrombauts / parse_version_numbers.php
Last active March 14, 2019 10:00
Parse version numbers into major/minor/patch values
<?php
$versions = array('1.0 RC1', '1.0 RC2', '1.0 RC3', '1.0 RC4', '1.0 RC5', '1.0 RC6', '1.5.0', '1.5.1', '1.5.10', '1.5.11', '1.5.12', '1.5.13', '1.5.14', '1.5.15', '1.5.2', '1.5.3', '1.5.4', '1.5.5', '1.5.6', '1.5.7', '1.5.8', '1.5.9', '1.6.0', '1.6.1', '1.6.2', '1.6.3', '1.6.4', '1.6.5', '1.6.6', '1.6.7', '5.3.5-1ubuntu7.11', '2.14 RC1', '3.12RC5');
foreach($versions as $version)
{
$result = preg_match("/^(\d+)\.(\d+)[\. \-]?([a-z0-9\-\.]+)$/i", $version, $matches);
if($result)
{
$major = (int) $matches[1];
@stevenrombauts
stevenrombauts / grab_date.php
Last active December 26, 2015 05:19
Try to extract the date from filenames by guessing with different formats.
<?php
/**
* Run over different date patterns
* and attempt to extract the correct date from a given string.
*
* @param String containing date.
* @return date in the YYYY-MM-DD format, or FALSE if no match was found.
**/
function grab_date($str)
{