- Баллы
- 76
- Имя в Minecraft
- _WeekThor_
Можно ли с помощью PHP заменить "§6Text" на "Text" , Знаю, что можно, но какой функцией и как?
Следуйте инструкциям в видео ниже, чтобы узнать, как установить наш сайт как веб-приложение на главный экран вашего устройства.
Примечание: Эта функция может быть недоступна в некоторых браузерах.
(str|preg)_replaceМожно ли с помощью PHP заменить "§6Text" на "Text" , Знаю, что можно, но какой функцией и как?
На поверхности всё ещё сложнее, так как предположительно нужно обрамлять HTML тэгами.(str|preg)_replace
Что-то подобное вообщем.На поверхности всё ещё сложнее, так как предположительно нужно обрамлять HTML тэгами.
$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, не хочу в этом копаться)Что-то подобное вообщем.
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>'; }
Ток не бомбе плез, если шо. Выслушаю критику
Но ведь так проблема не пропадает. Если в середине текста он должен стать жирным то он так и останется им до конца.Форматирование работать не будет (&c + &l). Заменяй только открывающими тегами, а все закрывающие ставь в самом конце строки.
<?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.';
А где у тебя сайт?)Классно, добавил себе на сайт.
Он ещё не готов, вот - http://mineonyx.com/А где у тебя сайт?)![]()