fork(1) 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.  
  11. function makeFirstLetterUppercase($text) {
  12. $chars = preg_split('//u', $text, -1, PREG_SPLIT_NO_EMPTY);
  13. $chars[0] = mb_strtoupper($chars[0]);
  14. $sentence = implode('', $chars);
  15. return $sentence;
  16. }
  17.  
  18. function fixText($text) {
  19. $matches = array();
  20. $matches = splitText($text);
  21. $result = '';
  22. foreach($matches as $match) {
  23. $match = preg_replace('/(^\s+)/u', '', $match);
  24. $match = makeFirstLetterUppercase($match);
  25. $result .= $match;
  26. }
  27. //$result = preg_replace('/([,.;:!?])/ui')
  28. }
  29.  
  30. function splitText($text) {
  31. $matches = preg_split("/(?<=[?!.])/u", $text, -1, PREG_SPLIT_NO_EMPTY);
  32. return $matches;
  33. }
  34.  
  35.  
  36. $result = fixText($text);
  37. echo "{$result}\n";
  38.  
  39.  
Success #stdin #stdout 0.02s 52488KB
stdin
Standard input is empty
stdout