本文整理汇总了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;
}
示例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;
}