false, 'raw' => substr( $raw, 0, 64 ), 'major' => 0, 'minor' => 0, 'patch' => 0, 'branch' => '', 'suffix' => '', 'vendor' => false, 'prerelease' => false, ); if ( ! preg_match( '/^(\d{1,2})\.(\d{1,3})\.(\d{1,3})(.*)$/s', $raw, $m ) ) { return $result; } $suffix = $m[4]; // Anything after the numeric triplet must start with a separator or a pre-release tag. if ( '' !== $suffix && ! preg_match( '/^[-+~_.A-Za-z]/', $suffix ) ) { return $result; } // A bare letter run glued to the patch number is only valid as a pre-release tag (8.4.27RC1). if ( preg_match( '/^[A-Za-z]/', $suffix ) && ! preg_match( '/^(alpha|beta|rc|dev|a\d|b\d)/i', $suffix ) ) { return $result; } $result['valid'] = true; $result['major'] = (int) $m[1]; $result['minor'] = (int) $m[2]; $result['patch'] = (int) $m[3]; $result['branch'] = $result['major'] . '.' . $result['minor']; $result['suffix'] = substr( $suffix, 0, 48 ); if ( '' !== $suffix ) { if ( preg_match( '/^[-~_.]?(alpha|beta|rc|dev|a\d|b\d)/i', $suffix ) ) { $result['prerelease'] = true; } else { $result['vendor'] = true; } } return $result; } /** Compare branch strings numerically: returns <0, 0, >0. */ public static function compare_branch( $a, $b ) { return version_compare( $a . '.0', $b . '.0' ); } }