/
al.anatolyev
/
web4stud
Обзор
Документация
Войти
/
al.anatolyev
/
web4stud
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
tools/lorem.php
55 строк
2 KB
aag
%1
19 май 2026, 12:36
19 май 2026, 12:36
1775bad
Код
Авторство
О чём код?
<?php define("LAT2CYR",1); // not translit, but define("CYR2LAT",0); const RUS = CYR2LAT; const LAT = LAT2CYR; function translit($direction, $text):string { $alphabet = [ "А"=>"A", "Б"=>"B", "В"=>"V", "Г"=>"G", "Д"=>"D", "Е"=>"E", "Ё"=>"Yo", "Ж"=>"Zh", "З"=>"Z", "И"=>"I", "Й"=>"Y", "К"=>"K", "Л"=>"L", "М"=>"M", "Н"=>"N", "О"=>"O", "П"=>"P", "Р"=> "R", "С"=>"S", "Т"=>"T", "У"=>"U", "Ф"=>"F", "Х"=>"Kh", "Ц"=>"Ts","Ч"=>"Ch", "Ш"=>"Sh", "Щ"=>"Shch","Ъ"=>"`", "Ы"=>"Y","Ь"=>"`","Ю"=>"Yu", "Я"=>"Ya", "Ку"=>"Q", "а"=>"a", "б"=>"b", "в"=>"v", "г"=>"g", "д"=>"d", "е"=>"e", "ё"=>"yo", "ж"=>"zh", "з"=>"z", "и"=>"i", "й"=>"y", "к"=>"k", "л"=>"l", "м"=>"m", "н"=>"n", "о"=>"o", "п"=>"p", "р"=> "r", "с"=>"s", "т"=>"t", "у"=>"u", "ф"=>"f", "х"=>"kh", "ц"=>"ts","ч"=>"ch", "ш"=>"sh", "щ"=>"shch","ъ"=>"`", "ы"=>"y","ь"=>"`","ю"=>"yu", "я"=>"ya", "ку"=>"q", ]; return $direction == CYR2LAT ? strtr($text, array_flip($alphabet)) : strtr($text, $alphabet); } function getLorem($dir, $paragraphs_count, $tenses_count) { $lorem = file('lorem.text'); $h2 = "Lorem Ipsum Dolor sit Amet"; //mb_strcut($lorem[0], 0, rand(20, 30)); $h3 = $text = $html = ""; for ($i = 0; $i < $paragraphs_count; $i ++) { shuffle($lorem); $a = array_slice($lorem, 0, $tenses_count); $h3 = mb_strcut($a[1], 0, rand(20, 40)); $text = implode(' ', preg_replace("/\n/iu","", $a)); if ($dir == RUS) { $h2 = translit(CYR2LAT, $h2); $h3 = translit(CYR2LAT, $h3); $text = translit(CYR2LAT, $text); } $html.="<h3>$h3</h3>\n<p>$text</p>\n"; } return "<h2>$h2</h2>\n$html"; } echo htmlspecialchars(getLorem(LAT, 6, 10)); echo "<hr>"; echo htmlspecialchars(getLorem(RUS, 6, 10)); ?>