fork download
  1. <?php
  2.  
  3. $text1 = "ну что. не смотрел еще black mesa.я собирался скачать ,но все как-то некогда было.";
  4. $text2 = "roses are red,and violets are blue.whatever you do i'll keep it for you.";
  5. $text3 = "привет!есть 2 функции,preg_split и explode ,не понимаю,в чем между ними разница.";
  6.  
  7. /* Делает первую букву в строке заглавной */
  8. function makeFirstLetterUppercase($text) {
  9. $array = preg_split("/ *[.!?] */", $text, null, PREG_SPLIT_NO_EMPTY);
  10. foreach($array as $key => $value){
  11. $firstLetter = mb_strtoupper(mb_substr($value, 0, 1));
  12. $replace = $firstLetter.mb_substr($value, 1);
  13. $text = preg_replace("/ *$value */u", $replace, $text);
  14. // $txt = $txt.$firstLetter.mb_substr($value, 1).". ";
  15. }
  16. return $text;
  17. }
  18. /* исправляет текст */
  19. function fixText($text) {
  20. $array = array(",", "-", ".", "!");
  21. foreach($array as $k => $rE){
  22. $text = preg_replace("/ *[$rE] */", "$rE ", $text);
  23. }
  24. return $text;
  25. }
  26. $text1 = makeFirstLetterUppercase($text1);
  27. $result = fixText($text1);
  28. echo "{$result}\n";
  29. $text2 = makeFirstLetterUppercase($text2);
  30. $result = fixText($text2);
  31. echo "{$result}\n";
  32. $text3 = makeFirstLetterUppercase($text3);
  33. $result = fixText($text3);
  34. echo "{$result}\n";
  35.  
  36.  
Success #stdin #stdout 0.01s 20520KB
stdin
Standard input is empty
stdout
Ну что. Не смотрел еще black mesa. Я собирался скачать, но все как- то некогда было. 
Roses are red, and violets are blue. Whatever you do i'll keep it for you. 
Привет! Есть 2 функции, preg_split и explode, не понимаю, в чем между ними разница.