REDROOM
PHP 8.1.33
Path:
Logout
Edit File
Size: 2.50 KB
Close
/home/jambtst2015/www/framework/i18n/CChoiceFormat.php
Text
Base64
<?php /** * YiiBase class file. * * @author Qiang Xue <qiang.xue@gmail.com> * @link http://www.yiiframework.com/ * @copyright 2008-2013 Yii Software LLC * @license http://www.yiiframework.com/license/ */ /** * CChoiceFormat is a helper that chooses an appropriate message based on the specified number value. * The candidate messages are given as a string in the following format: * <pre> * 'expr1#message1|expr2#message2|expr3#message3' * </pre> * where each expression should be a valid PHP expression with <code>'n'</code> as the only variable. * For example, <code>'n==1'</code> and <code>'n%10==2 && n>10'</code> are both valid expressions. * The variable <code>'n'</code> will take the given number value, and if an expression evaluates true, * the corresponding message will be returned. * * For example, given the candidate messages <code>'n==1#one|n==2#two|n>2#others'</code> and * the number value 2, the resulting message will be <code>'two'</code>. * * For expressions like <code>'n==1'</code>, we can also use a shortcut <code>'1'</code>. So the above example * candidate messages can be simplified as <code>'1#one|2#two|n>2#others'</code>. * * In case the given number doesn't select any message, the last candidate message * will be returned. * * The PHP expressions will be evaluated using {@link evaluate}. * * @author Qiang Xue <qiang.xue@gmail.com> * @package system.i18n */ class CChoiceFormat { /** * Formats a message according to the specified number value. * @param string $messages the candidate messages in the format of 'expr1#message1|expr2#message2|expr3#message3'. * See {@link CChoiceFormat} for more details. * @param mixed $number the number value * @return string the selected message */ public static function format($messages, $number) { $n=preg_match_all('/\s*([^#]*)\s*#([^\|]*)\|/',$messages.'|',$matches); if($n===0) return $messages; for($i=0;$i<$n;++$i) { $expression=$matches[1][$i]; $message=$matches[2][$i]; if($expression===(string)(int)$expression) { if($expression==$number) return $message; } elseif(self::evaluate(str_replace('n','$n',$expression),$number)) return $message; } return $message; // return the last choice } /** * Evaluates a PHP expression with the given number value. * @param string $expression the PHP expression * @param mixed $n the number value * @return boolean the expression result */ protected static function evaluate($expression,$n) { return @eval("return $expression;"); } }
Save
Close
Exit & Reset
Text mode: syntax highlighting auto-detects file type.
Directory Contents
Dirs: 2 × Files: 9
Delete Selected
Select All
Select None
Sort:
Name
Size
Modified
Enable drag-to-move
Name
Size
Perms
Modified
Actions
data
DIR
-
drwxr-xr-x
2024-11-22 17:53:16
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
gettext
DIR
-
drwxr-xr-x
2025-10-15 12:54:04
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
CChoiceFormat.php
2.50 KB
lrw-r--r--
2024-11-22 17:53:16
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
CDateFormatter.php
16.86 KB
lrw-r--r--
2024-11-22 17:53:16
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
CDbMessageSource.php
4.43 KB
lrw-r--r--
2024-11-22 17:53:16
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
CGettextMessageSource.php
3.76 KB
lrw-r--r--
2024-11-22 17:53:16
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
CLocale.php
13.87 KB
lrw-r--r--
2024-11-22 17:53:16
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
CMessageSource.php
5.34 KB
lrw-r--r--
2024-11-22 17:53:16
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
CNumberFormatter.php
10.53 KB
lrw-r--r--
2024-11-22 17:53:16
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
CPhpMessageSource.php
5.87 KB
lrw-r--r--
2024-11-22 17:53:16
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
error_log
53.03 KB
lrw-r--r--
2025-11-05 00:57:48
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
Zip Selected
If ZipArchive is unavailable, a
.tar
will be created (no compression).