fork(1) download
  1. <?php
  2.  
  3.  
  4. $text = ' привет.есть 2 функции,preg_split и explode ,не понимаю,в чем между ними разница. васса,это борода.';
  5.  
  6. function makeFirstLetterUppercase($text) {
  7. $parts = preg_split('/(?<=[.!?])/u', $text, 0, PREG_SPLIT_NO_EMPTY);
  8. $result = '';
  9. foreach($parts as $key => $sentence) {
  10. $sentence = trim($sentence);
  11. $otherPart = mb_substr($sentence, 1);
  12. $firstLetter = mb_strtoupper(mb_substr($sentence, 0, 1));
  13. $result = $firstLetter . $otherPart;
  14. }
  15. return $result;
  16. }
  17.  
  18. function fixText($text) {
  19. $regexpTooManySpaces = '/\\s*([.,!?;])\\s*/';
  20. $result = preg_replace($regexpTooManySpaces, '$1 ', $text);
  21. return $result;
  22. }
  23. //echo makeFirstLetterUppercase($text);
  24. $text = makeFirstLetterUppercase($text);
  25. $text = fixText($text);
  26. echo $text;
  27.  
  28.  
  29.  
  30.  
Success #stdin #stdout 0.01s 20568KB
stdin
Standard input is empty
stdout
Васса, это борода.