本文整理匯總了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;
}