fork(2) download
  1. <?php
  2.  
  3.  
  4. $text = "ну что. не смотрел еще black mesa.я собирался скачать ,но все как-то некогда было.";
  5. // Для тестов
  6. $text1 = "roses are red,and violets are blue.whatever you do i'll keep it for you.";
  7. $text2 = "привет.есть 2 функции,preg_split и explode ,не понимаю,в чем между ними разница.";
  8.  
  9. /* Делает первую букву в строке заглавной */
  10. function makeFirstLetterUppercase($text) {
  11. // $matches = [];
  12. $firstLetter = "/^[а-яёa-z]/u";
  13. preg_match($firstLetter, $text, $match);
  14. $match[0] = mb_strtoupper($match[0]);
  15. $text = preg_replace($firstLetter, $match[0], $text, $limit = 1);
  16. $regexp = "/[.!?] *[а-яёa-z]/u";
  17. preg_match_all($regexp, $text, $matches);
  18. foreach($matches as $null => $replacement){
  19. foreach($replacement as $nothing => $replacer){
  20. $pattern = $replacer;
  21. $replacer = mb_strtoupper($replacer);
  22. $text = str_replace($pattern, $replacer, $text);
  23. }
  24. }
  25. return $text;
  26. }
  27. /*исправляет текст */
  28. function fixText($text) {
  29. $mP = [
  30. ". " => "/ *[.] */",
  31. "? " => "/ *[?] */",
  32. ", " => "/ *[,] */",
  33. "! " => "/ *[!] */"];
  34. foreach($mP as $m => $p){
  35. $text = preg_replace($p, $m, $text);
  36. }
  37. return $text;
  38. }
  39. $text = makeFirstLetterUppercase($text);
  40. $result = fixText($text);
  41. echo "{$result}\n";
  42. $text1 = makeFirstLetterUppercase($text1);
  43. $result = fixText($text1);
  44. echo "{$result}\n";
  45. $text2 = makeFirstLetterUppercase($text2);
  46. $result = fixText($text2);
  47. echo "{$result}\n";
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, не понимаю, в чем между ними разница.