Advertisement
Guest User

Untitled

a guest
Oct 9th, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. <?php
  2.  
  3. error_reporting(-1);
  4. mb_internal_encoding('utf-8');
  5.  
  6. // function to pick a letter from array of strings at certain index from each string and wrap it in non-breaking spaces
  7.  
  8. function mapper($array,$i){
  9. $newArray=[];
  10. for ($x=0;$x<count($array);$x++){
  11.  
  12. $symbol=mb_substr($array[$x],$i,1);
  13.  
  14. if ($symbol==" "||!$symbol){
  15. array_push($newArray,"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
  16. }
  17. elseif (preg_match('/[ы]/u',$symbol)) {
  18. array_push($newArray, "&nbsp;&nbsp;&nbsp;&nbsp;" . $symbol . "&nbsp;&nbsp;&nbsp;&nbsp;");
  19. }
  20. elseif (preg_match('/[А-Я]/u',$symbol)) {
  21. array_push($newArray, "&nbsp;&nbsp;&nbsp;&nbsp;" . $symbol . "&nbsp;&nbsp;&nbsp;&nbsp");
  22. }
  23. elseif (preg_match('/[а-яё]/u',$symbol)) {
  24. array_push($newArray, "&nbsp;&nbsp;&nbsp;&nbsp;" . $symbol . "&nbsp;&nbsp;&nbsp;&nbsp;");
  25. }
  26.  
  27. elseif (preg_match('/[.,]/u',$symbol)) {
  28. array_push($newArray,"&nbsp;&nbsp;&nbsp;&nbsp;" . $symbol . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp");
  29. }
  30. else {
  31. array_push($newArray,"&nbsp;&nbsp;&nbsp;" . $symbol . "&nbsp;&nbsp;&nbsp;");
  32. }
  33.  
  34.  
  35.  
  36. }
  37. return $newArray;
  38. }
  39.  
  40.  
  41. $text =
  42. "Дым табачный воздух выел.
  43. Комната —
  44. глава в крученыховском аде.
  45. Вспомни —
  46. за этим окном
  47. впервые
  48. руки твои, исступлённый, гладил.
  49. Сегодня сидишь вот,
  50. сердце в железе.
  51. День ещё —
  52. выгонишь,
  53. может быть, изругав.
  54. В мутной передней долго не влезет
  55. сломанная дрожью рука в рукав.";
  56.  
  57. //into array of strings
  58.  
  59. $split=preg_split('/\n/',$text);
  60.  
  61. //next steps are to determine longest string in array of strings (to use it as base for iteration duration)
  62.  
  63. $copyToDetermineLongest=$split;
  64. uasort($copyToDetermineLongest, function ($a,$b) {return mb_strlen($a)<mb_strlen($b);});
  65.  
  66. $longest=array_values($copyToDetermineLongest)[0];
  67. $string="";
  68.  
  69. //next steps are to cycle through array of strings with mapper() adding result of ech iteration into string with newline break
  70.  
  71. for ($i=0;$i<mb_strlen($longest);$i++){
  72.  
  73. $string = $string . implode('|',mapper($split,$i)) . "|\n";
  74.  
  75.  
  76. }
  77. echo "".nl2br($string);
  78. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement