Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- error_reporting(-1);
- mb_internal_encoding('utf-8');
- // function to pick a letter from array of strings at certain index from each string and wrap it in non-breaking spaces
- function mapper($array,$i){
- $newArray=[];
- for ($x=0;$x<count($array);$x++){
- $symbol=mb_substr($array[$x],$i,1);
- if ($symbol==" "||!$symbol){
- array_push($newArray,"   ");
- }
- elseif (preg_match('/[ы]/u',$symbol)) {
- array_push($newArray, " " . $symbol . " ");
- }
- elseif (preg_match('/[А-Я]/u',$symbol)) {
- array_push($newArray, " " . $symbol . "  ");
- }
- elseif (preg_match('/[а-яё]/u',$symbol)) {
- array_push($newArray, " " . $symbol . " ");
- }
- elseif (preg_match('/[.,]/u',$symbol)) {
- array_push($newArray," " . $symbol . "  ");
- }
- else {
- array_push($newArray," " . $symbol . " ");
- }
- }
- return $newArray;
- }
- $text =
- "Дым табачный воздух выел.
- Комната —
- глава в крученыховском аде.
- Вспомни —
- за этим окном
- впервые
- руки твои, исступлённый, гладил.
- Сегодня сидишь вот,
- сердце в железе.
- День ещё —
- выгонишь,
- может быть, изругав.
- В мутной передней долго не влезет
- сломанная дрожью рука в рукав.";
- //into array of strings
- $split=preg_split('/\n/',$text);
- //next steps are to determine longest string in array of strings (to use it as base for iteration duration)
- $copyToDetermineLongest=$split;
- uasort($copyToDetermineLongest, function ($a,$b) {return mb_strlen($a)<mb_strlen($b);});
- $longest=array_values($copyToDetermineLongest)[0];
- $string="";
- //next steps are to cycle through array of strings with mapper() adding result of ech iteration into string with newline break
- for ($i=0;$i<mb_strlen($longest);$i++){
- $string = $string . implode('|',mapper($split,$i)) . "|\n";
- }
- echo "".nl2br($string);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement