Войти или зарегистрироваться
  • Вы находитесь в сообществе Rubukkit. Мы - администраторы серверов Minecraft, разрабатываем собственные плагины и переводим на различные языки плагины наших коллег из других стран.
  • Данный раздел создан исключительно для релизов! Вопросы по лаунчеру или обвязке задавайте ТОЛЬКО в соответсвующей теме автора. Любые другие темы будут удалены, а авторы понесут наказание.

Веб Web-форма для rcon сессии

Можно ли с помощью PHP заменить "§6Text" на "Text" , Знаю, что можно, но какой функцией и как?
 
На поверхности всё ещё сложнее, так как предположительно нужно обрамлять HTML тэгами.
Что-то подобное вообщем.

PHP:
$string = '&6Hello &eWorld&0!';
$isset = false;
$htmlColors = ['&r'=>'#000', '&0' => ... ];

foreach(preg_match(..., $string) as $str) {
    $replacement = (($isset) ? '</span>' : '') . '<span style="color: ' .  $htmlColors[$str] . '">';
    preg_replace($str, $replacement, $string, 1);
    $isset = true;
}
if ($isset === true) {
    $string .= '</span>';
}

Ток не бомбе плез, если шо. Выслушаю критику
 
Что-то подобное вообщем.

PHP:
$string = '&6Hello &eWorld&0!';
$isset = false;
$htmlColors = ['&r'=>'#000', '&0' => ... ];

foreach(preg_match(..., $string) as $str) {
    $replacement = (($isset) ? '</span>' : '') . '<span style="color: ' .  $htmlColors[$str] . '">';
    preg_replace($str, $replacement, $string, 1);
    $isset = true;
}
if ($isset === true) {
    $string .= '</span>';
}

Ток не бомбе плез, если шо. Выслушаю критику
Забываешь про §r, не хочу в этом копаться)
 
Форматирование работать не будет (&c + &l). Заменяй только открывающими тегами, а все закрывающие ставь в самом конце строки.
Но ведь так проблема не пропадает. Если в середине текста он должен стать жирным то он так и останется им до конца.
 
PHP:
<?php

$styles = [
    '&0' => '<span style="color: #000;">', '&1' => '<span style="color: #00a;">',
    '&2' => '<span style="color: #0a0;">', '&3' => '<span style="color: #0aa;">',
    '&4' => '<span style="color: #a00;">', '&5' => '<span style="color: #a0a;">',
    '&6' => '<span style="color: #fa0;">', '&7' => '<span style="color: #aaa;">',
    '&8' => '<span style="color: #555;">', '&9' => '<span style="color: #55f;">',
    '&a' => '<span style="color: #5f5;">', '&b' => '<span style="color: #5ff;">',
    '&c' => '<span style="color: #f55;">', '&d' => '<span style="color: #f5f;">',
    '&e' => '<span style="color: #ff5;">', '&f' => '<span style="color: #fff;">',
    '&k' => '<span class="text-obfuscated">', '&l' => '<span style="font-weight: bold;">',
    '&m' => '<span style="text-decoration: line-through;">', '&n' => '<span style="text-decoration: underline;">',
    '&o' => '<span style="font-style: italic;">', '&r' => '<span style="color: #000; font-weight: normal; text-decoration: none;">',
];

$text = 'Lorem Ipsum is &asimply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy text ever since the &b1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining &2essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and &kmore recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.';

$text = str_replace(array_keys($styles), array_values($styles), $text, $count);

for($i=0;$i<$count;$i++){ $text .= '</span>'; }

?>
 
Последнее редактирование:
PHP:
$text = 'Lorem Ipsum is &asimply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the &b1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining &2essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and &kmore recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.';
Обрати внимание на эту строку и подумай почему твое решение работать не будет...
 
Классно, добавил себе на сайт.
А где у тебя сайт?)
emoticon-2867-src-f02f9d40f66f0840-28x28.png
 

Поделиться этой страницей

Назад
Верх