asdsadasd - PHP Online
Form of PHP Sandbox
Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php
in the places where the PHP script should be executed.
Result of php executing
Full code of asdsadasd.php
- <?php
- /**
- * Типо Куки)
- */
- $COOKIE = array(
- 'lang' => 'ru'
- );
- /**
- * Параметры?
- */
- $GLOBALS = array(
- 'LANG' => array(
- 'RU' => array(
- 'TITLE_TECHNICAL' => 'Техника',
- 'TOURNAMENT_BLOCK_LETF_HEADER' => 'Блок турниров',
- ),
- 'EN' => array(
- 'TITLE_TECHNICAL' => 'Technic'
- )
- )
- );
- /**
- * Класс локализатора
- */
- class Locale
- {
- /* Массив строк локализации */
- protected $_MESSAGES = array();
- /* Текущий язык */
- protected $locale;
- protected $locale_fallback = 'RU';
- public function __construct($lang = 'ru')
- {
- $this->locale = strtoupper($lang);
- $this->loadMessages();
- }
- protected function loadMessages()
- {
- if (isset($GLOBALS['LANG'][$this->locale])) {
- $this->_MESSAGES = $GLOBALS['LANG'][$this->locale];
- } else {
- $this->_MESSAGES = $GLOBALS['LANG'][$this->locale_fallback];
- }
- }
- public function get($key = '')
- {
- if (isset($this->_MESSAGES[$key])) {
- return $this->_MESSAGES[$key];
- }
- return strtoupper($key);
- }
- }
- /**
- * Функция для получения текущего языка (передаю сюда массив куки из за ограниченной области видимости)
- */
- function getAppLocale($default = 'ru', $COOKIE)
- {
- return isset($COOKIE['lang']) ? $COOKIE['lang'] : $default;
- }
- /**
- * Получаем текущий язык юзера и инициализируем класс локализатора
- */
- $currentLang = getAppLocale('ru', $COOKIE);
- $locale = new Locale($currentLang);
- /**
- * Получаем нужные нам строку локали по ключам
- */
- $myCustomLocaleString = $locale->get('TITLE_TECHNICAL');
- $myCustomLocaleStringTwo = $locale->get('TEST_STRING');
- $tournamentBlockLeftHeader = $locale->get('TOURNAMENT_BLOCK_LETF_HEADER');
- print_r(array(
- $myCustomLocaleString,
- $myCustomLocaleStringTwo,
- $tournamentBlockLeftHeader
- ));
File Description
- asdsadasd
- PHP Code
- 09 Jan-2021
- 2.09 Kb
You can Share it:
Latest PHP Pastes