fork download
  1. <?php
  2.  
  3.  
  4. $text = "ну что. не смотрел еще black mesa.я собирался скачать ,но все как-то некогда было.";
  5. // Для тестов
  6. // $text = 'roses are red,and violets are blue.whatever you do i'll keep it for you.';
  7. // $text = 'привет.есть 2 функции,preg_split и explode ,не понимаю,в чем между ними разница.';
  8.  
  9. /* исправляет текст */
  10. function fixText($text) {
  11. $regexp = "/(\\s+)?(,|[.!?])(\\s+)?/u";
  12. $temp = preg_replace($regexp, "$2 ", $text);
  13. $temp = rtrim($temp);
  14.  
  15. $temp = preg_split("//u", $temp, -1, PREG_SPLIT_NO_EMPTY);
  16.  
  17. var_dump($temp);
  18.  
  19. $temp[0] = mb_strtoupper($temp[0]);
  20.  
  21. var_dump($temp);
  22.  
  23. for ($i = 0; $i < (count($temp) - 2); $i++) {
  24. if (($temp[$i] == "." || $temp[$i] == "!" || $temp[$i] == "?") && ($temp[$i + 1] == " ")){
  25. $temp[$i + 2] = mb_strtoupper($temp[$i + 2]);
  26. }
  27. }
  28. $temp = implode($temp);
  29.  
  30. return $temp;
  31. }
  32.  
  33. $result = fixText($text);
  34. echo "{$result}\n";
  35.  
Success #stdin #stdout 0.02s 24448KB
stdin
Standard input is empty
stdout
array(83) {
  [0]=>
  string(2) "н"
  [1]=>
  string(2) "у"
  [2]=>
  string(1) " "
  [3]=>
  string(2) "ч"
  [4]=>
  string(2) "т"
  [5]=>
  string(2) "о"
  [6]=>
  string(1) "."
  [7]=>
  string(1) " "
  [8]=>
  string(2) "н"
  [9]=>
  string(2) "е"
  [10]=>
  string(1) " "
  [11]=>
  string(2) "с"
  [12]=>
  string(2) "м"
  [13]=>
  string(2) "о"
  [14]=>
  string(2) "т"
  [15]=>
  string(2) "р"
  [16]=>
  string(2) "е"
  [17]=>
  string(2) "л"
  [18]=>
  string(1) " "
  [19]=>
  string(2) "е"
  [20]=>
  string(2) "щ"
  [21]=>
  string(2) "е"
  [22]=>
  string(1) " "
  [23]=>
  string(1) "b"
  [24]=>
  string(1) "l"
  [25]=>
  string(1) "a"
  [26]=>
  string(1) "c"
  [27]=>
  string(1) "k"
  [28]=>
  string(1) " "
  [29]=>
  string(1) "m"
  [30]=>
  string(1) "e"
  [31]=>
  string(1) "s"
  [32]=>
  string(1) "a"
  [33]=>
  string(1) "."
  [34]=>
  string(1) " "
  [35]=>
  string(2) "я"
  [36]=>
  string(1) " "
  [37]=>
  string(2) "с"
  [38]=>
  string(2) "о"
  [39]=>
  string(2) "б"
  [40]=>
  string(2) "и"
  [41]=>
  string(2) "р"
  [42]=>
  string(2) "а"
  [43]=>
  string(2) "л"
  [44]=>
  string(2) "с"
  [45]=>
  string(2) "я"
  [46]=>
  string(1) " "
  [47]=>
  string(2) "с"
  [48]=>
  string(2) "к"
  [49]=>
  string(2) "а"
  [50]=>
  string(2) "ч"
  [51]=>
  string(2) "а"
  [52]=>
  string(2) "т"
  [53]=>
  string(2) "ь"
  [54]=>
  string(1) ","
  [55]=>
  string(1) " "
  [56]=>
  string(2) "н"
  [57]=>
  string(2) "о"
  [58]=>
  string(1) " "
  [59]=>
  string(2) "в"
  [60]=>
  string(2) "с"
  [61]=>
  string(2) "е"
  [62]=>
  string(1) " "
  [63]=>
  string(2) "к"
  [64]=>
  string(2) "а"
  [65]=>
  string(2) "к"
  [66]=>
  string(1) "-"
  [67]=>
  string(2) "т"
  [68]=>
  string(2) "о"
  [69]=>
  string(1) " "
  [70]=>
  string(2) "н"
  [71]=>
  string(2) "е"
  [72]=>
  string(2) "к"
  [73]=>
  string(2) "о"
  [74]=>
  string(2) "г"
  [75]=>
  string(2) "д"
  [76]=>
  string(2) "а"
  [77]=>
  string(1) " "
  [78]=>
  string(2) "б"
  [79]=>
  string(2) "ы"
  [80]=>
  string(2) "л"
  [81]=>
  string(2) "о"
  [82]=>
  string(1) "."
}
array(83) {
  [0]=>
  string(2) "Н"
  [1]=>
  string(2) "у"
  [2]=>
  string(1) " "
  [3]=>
  string(2) "ч"
  [4]=>
  string(2) "т"
  [5]=>
  string(2) "о"
  [6]=>
  string(1) "."
  [7]=>
  string(1) " "
  [8]=>
  string(2) "н"
  [9]=>
  string(2) "е"
  [10]=>
  string(1) " "
  [11]=>
  string(2) "с"
  [12]=>
  string(2) "м"
  [13]=>
  string(2) "о"
  [14]=>
  string(2) "т"
  [15]=>
  string(2) "р"
  [16]=>
  string(2) "е"
  [17]=>
  string(2) "л"
  [18]=>
  string(1) " "
  [19]=>
  string(2) "е"
  [20]=>
  string(2) "щ"
  [21]=>
  string(2) "е"
  [22]=>
  string(1) " "
  [23]=>
  string(1) "b"
  [24]=>
  string(1) "l"
  [25]=>
  string(1) "a"
  [26]=>
  string(1) "c"
  [27]=>
  string(1) "k"
  [28]=>
  string(1) " "
  [29]=>
  string(1) "m"
  [30]=>
  string(1) "e"
  [31]=>
  string(1) "s"
  [32]=>
  string(1) "a"
  [33]=>
  string(1) "."
  [34]=>
  string(1) " "
  [35]=>
  string(2) "я"
  [36]=>
  string(1) " "
  [37]=>
  string(2) "с"
  [38]=>
  string(2) "о"
  [39]=>
  string(2) "б"
  [40]=>
  string(2) "и"
  [41]=>
  string(2) "р"
  [42]=>
  string(2) "а"
  [43]=>
  string(2) "л"
  [44]=>
  string(2) "с"
  [45]=>
  string(2) "я"
  [46]=>
  string(1) " "
  [47]=>
  string(2) "с"
  [48]=>
  string(2) "к"
  [49]=>
  string(2) "а"
  [50]=>
  string(2) "ч"
  [51]=>
  string(2) "а"
  [52]=>
  string(2) "т"
  [53]=>
  string(2) "ь"
  [54]=>
  string(1) ","
  [55]=>
  string(1) " "
  [56]=>
  string(2) "н"
  [57]=>
  string(2) "о"
  [58]=>
  string(1) " "
  [59]=>
  string(2) "в"
  [60]=>
  string(2) "с"
  [61]=>
  string(2) "е"
  [62]=>
  string(1) " "
  [63]=>
  string(2) "к"
  [64]=>
  string(2) "а"
  [65]=>
  string(2) "к"
  [66]=>
  string(1) "-"
  [67]=>
  string(2) "т"
  [68]=>
  string(2) "о"
  [69]=>
  string(1) " "
  [70]=>
  string(2) "н"
  [71]=>
  string(2) "е"
  [72]=>
  string(2) "к"
  [73]=>
  string(2) "о"
  [74]=>
  string(2) "г"
  [75]=>
  string(2) "д"
  [76]=>
  string(2) "а"
  [77]=>
  string(1) " "
  [78]=>
  string(2) "б"
  [79]=>
  string(2) "ы"
  [80]=>
  string(2) "л"
  [81]=>
  string(2) "о"
  [82]=>
  string(1) "."
}
Ну что. Не смотрел еще black mesa. Я собирался скачать, но все как-то некогда было.