当前位置: 首页>>代码示例>>PHP>>正文


PHP TimeExpressionParser::getSettingsForLanguage方法代码示例

本文整理汇总了PHP中TimeExpressionParser::getSettingsForLanguage方法的典型用法代码示例。如果您正苦于以下问题:PHP TimeExpressionParser::getSettingsForLanguage方法的具体用法?PHP TimeExpressionParser::getSettingsForLanguage怎么用?PHP TimeExpressionParser::getSettingsForLanguage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TimeExpressionParser的用法示例。


在下文中一共展示了TimeExpressionParser::getSettingsForLanguage方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: caSortableValue

/**
 * Convert text into string suitable for sorting, by moving articles to end of string, etc.
 *
 * @param string $ps_text Text to convert to sortable value
 * @param array $pa_options Options include:
 *		locale = Locale settings to use. If omitted current default locale is used. [Default is current locale]
 *		omitArticle = Omit leading definite and indefinited articles, rather than moving them to the end of the text [Default is true]
 *
 * @return string Converted text. If locale cannot be found $ps_text is returned unchanged.
 */
function caSortableValue($ps_text, $pa_options = null)
{
    global $g_ui_locale;
    $ps_locale = caGetOption('locale', $pa_options, $g_ui_locale);
    if (!$ps_locale) {
        return $ps_text;
    }
    $pb_omit_article = caGetOption('omitArticle', $pa_options, true);
    $o_locale_settings = TimeExpressionParser::getSettingsForLanguage($ps_locale);
    $vs_display_value = trim(preg_replace('![^\\p{L}0-9 ]+!u', ' ', $ps_text));
    // Move articles to end of string
    $va_definite_articles = $o_locale_settings ? $o_locale_settings->get('definiteArticles') : array();
    $va_indefinite_articles = $o_locale_settings ? $o_locale_settings->get('indefiniteArticles') : array();
    foreach (array($va_definite_articles, $va_indefinite_articles) as $va_articles) {
        if (is_array($va_articles)) {
            foreach ($va_articles as $vs_article) {
                if (preg_match('!^(' . $vs_article . ')[ ]+!i', $vs_display_value, $va_matches)) {
                    $vs_display_value = trim(str_replace($va_matches[1], '', $vs_display_value) . ($pb_omit_article ? '' : ', ' . $va_matches[1]));
                    break 2;
                }
            }
        }
    }
    // Left-pad numbers
    if (preg_match("![\\d]+!", $vs_display_value, $va_matches)) {
        for ($i = 0; $i < sizeof($va_matches); $i++) {
            $vs_padded = str_pad($va_matches[$i], 15, 0, STR_PAD_LEFT);
            $vs_display_value = str_replace($va_matches[$i], $vs_padded, $vs_display_value);
        }
    }
    return $vs_display_value;
}
开发者ID:samrahman,项目名称:providence,代码行数:42,代码来源:utilityHelpers.php

示例2: caSortableValue

/**
 * Convert text into string suitable for sorting, by moving articles to end of string, etc.
 *
 * @param string $ps_text Text to convert to sortable value
 * @param array $pa_options Options include:
 *		locale = Locale settings to use. If omitted current default locale is used. [Default is current locale]
 *
 * @return string Converted text. If locale cannot be found $ps_text is returned unchanged.
 */
function caSortableValue($ps_text, $pa_options = null)
{
    global $g_ui_locale;
    $ps_locale = caGetOption('locale', $pa_options, $g_ui_locale);
    if (!$ps_locale) {
        return $ps_text;
    }
    $o_locale_settings = TimeExpressionParser::getSettingsForLanguage($ps_locale);
    $vs_display_value = trim(preg_replace('![^\\p{L}0-9 ]+!u', ' ', $ps_text));
    $va_definite_articles = $o_locale_settings->get('definiteArticles');
    $va_indefinite_articles = $o_locale_settings->get('indefiniteArticles');
    foreach (array($va_definite_articles, $va_indefinite_articles) as $va_articles) {
        if (is_array($va_articles)) {
            foreach ($va_articles as $vs_article) {
                if (preg_match('!^(' . $vs_article . ')[ ]+!i', $vs_display_value, $va_matches)) {
                    $vs_display_value = trim(str_replace($va_matches[1], '', $vs_display_value) . ', ' . $va_matches[1]);
                    break 2;
                }
            }
        }
    }
    return $vs_display_value;
}
开发者ID:idiscussforum,项目名称:providence,代码行数:32,代码来源:utilityHelpers.php


注:本文中的TimeExpressionParser::getSettingsForLanguage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。