fork download
  1. <?php
  2.  
  3.  
  4. $text = ' привет.есть 2 функции,preg_split и explode ,не понимаю,в чем между ними разница. васса,это борода.';
  5. //$text = "ну что. не смотрел еще black mesa.я собирался скачать ,но все как-то некогда было.";
  6. //$text = "roses are red,and violets are blue.whatever you do i'll keep it for you.";
  7.  
  8. function makeFirstLetterUppercase($text) {
  9. $parts = preg_split('/(?<=[.!?])/u', $text, 0, PREG_SPLIT_NO_EMPTY);
  10. foreach($parts as $key => $sentence) {
  11. $sentence = trim($sentence);
  12. $otherPart = mb_substr($sentence, 1);
  13. $firstLetter = mb_strtoupper(mb_substr($sentence, 0, 1));
  14. $sentence = $firstLetter . $otherPart;
  15. $text = str_replace($parts[$key], $sentence, $text);
  16. }
  17. return $text;
  18. }
  19.  
  20. function fixText($text) {
  21. $regexpTooManySpaces = '/\\s*([.,!?;])\\s*/';
  22. $result = preg_replace($regexpTooManySpaces, '$1 ', $text);
  23. return $result;
  24. }
  25.  
  26. $text = makeFirstLetterUppercase($text);
  27. $text = fixText($text);
  28. echo $text;
Success #stdin #stdout 0.01s 20520KB
stdin
Standard input is empty
stdout
Привет. Есть 2 функции, preg_split и explode, не понимаю, в чем между ними разница. Васса, это борода.