rex_string::versionCompare PHP Method

versionCompare() public static method

In contrast to version_compare() it treats "1.0" and "1.0.0" as equal and it supports a space as separator for the version parts, e.g. "1.0 beta1"
See also: http://www.php.net/manual/en/function.version-compare.php
public static versionCompare ( string $version1, string $version2, string $comparator = null ) : integer | boolean
$version1 string First version number
$version2 string Second version number
$comparator string Optional comparator
return integer | boolean
    public static function versionCompare($version1, $version2, $comparator = null)
    {
        $version1 = self::versionSplit($version1);
        $version2 = self::versionSplit($version2);
        $max = max(count($version1), count($version2));
        $version1 = implode('.', array_pad($version1, $max, '0'));
        $version2 = implode('.', array_pad($version2, $max, '0'));
        return version_compare($version1, $version2, $comparator);
    }

Usage Example

 static function replaceVars($template, $er = array())
 {
     $r = rex_extension::registerPoint(new rex_extension_point('YFORM_EMAIL_BEFORE_REPLACEVARS', ['template' => $template, 'search_replace' => $er, 'status' => false]));
     $template = $r['template'];
     $er = $r['search_replace'];
     $status = $r['status'];
     if ($status) {
         return true;
     }
     $er['REX_SERVER'] = rex::getServer();
     $er['REX_ERROR_EMAIL'] = rex::getErrorEmail();
     $er['REX_SERVERNAME'] = rex::getServerName();
     $er['REX_NOTFOUND_ARTICLE_ID'] = rex_article::getNotfoundArticleId();
     $er['REX_ARTICLE_ID'] = rex_article::getCurrentId();
     $template['body'] = rex_var::parse($template['body'], '', 'yform_email_template', $er);
     $template['body_html'] = rex_var::parse($template['body_html'], '', 'yform_email_template', $er);
     // rex_vars bug: sonst wird der Zeilenumbruch entfernt - wenn DATA_VAR am Ende einer Zeile
     if (rex_string::versionCompare(rex::getVersion(), '5.0.1', '<')) {
         $template['body'] = str_replace("?>\r", "?>\r\n\r", $template['body']);
         $template['body'] = str_replace("?>\n", "?>\n\r\n", $template['body']);
         $template['body_html'] = str_replace("?>\r", "?>\r\n\r", $template['body_html']);
         $template['body_html'] = str_replace("?>\n", "?>\n\r\n", $template['body_html']);
     }
     $template['body'] = rex_file::getOutput(rex_stream::factory('yform/email/template/' . $template['name'] . '/body', $template['body']));
     $template['body_html'] = rex_file::getOutput(rex_stream::factory('yform/email/template/' . $template['name'] . '/body_html', $template['body_html']));
     return $template;
 }
All Usage Examples Of rex_string::versionCompare