fork(1) download
  1. <?php
  2.  
  3.  
  4. $textWithErrors = 'и что ты еще расскажешь,блинблинский.а что дальше?мм?ну и что .';
  5. $regexpAndCorrected = [
  6. "/[ ]*,[ ]*/u" => ", ",
  7. "/[ ]*\\.[ ]*/u" => ". ",
  8. "/[ ]*![ ]*/u" => "! ",
  9. "/[ ]*\\?[ ]*/u" => "? ",
  10. "/[ ]*\\:[ ]*/u" => ": "
  11. ];
  12. $regexpForSearchClause = "/(\\. |! |\\? )/u";
  13.  
  14. function correction($text, $regexp, $arrayMistakeCorrected) {
  15. echo "текст с ошибками:\n$text\n\n";
  16.  
  17. foreach ($arrayMistakeCorrected as $mistake => $corrected) {
  18. $text = preg_replace($mistake, $corrected, $text);
  19. }
  20.  
  21. $text = rtrim($text);
  22. echo "текст без ошибок:\n$text\n\n";
  23.  
  24. $clauses = [];
  25. $clauses = preg_split ($regexp, $text, -1, PREG_SPLIT_DELIM_CAPTURE);
  26.  
  27. foreach ($clauses as $key => $clause) {
  28.  
  29. $characters = preg_split('//u', $clause, -1, PREG_SPLIT_NO_EMPTY);
  30. $characters[0] = mb_strtoupper($characters[0]);
  31. $clause = implode ($characters);
  32.  
  33. var_dump ($clause);
  34. echo "\n\n";
  35.  
  36. }
  37.  
  38. $text = implode($clause);
  39.  
  40. return($text);
  41.  
  42. }
  43.  
  44. $textWithErrors = correction($textWithErrors, $regexpAndCorrected, $regexpForSearchClause);
  45.  
  46. print_r($textWithErrors);
  47. ?>
Success #stdin #stdout #stderr 0.02s 23740KB
stdin
Standard input is empty
stdout
текст с ошибками:
и что ты еще расскажешь,блинблинский.а что дальше?мм?ну и что .

текст без ошибок:
и что ты еще расскажешь,блинблинский.а что дальше?мм?ну и что .

stderr
PHP Warning:  Invalid argument supplied for foreach() in /home/3yIyqh/prog.php on line 18
PHP Warning:  preg_split() expects parameter 1 to be string, array given in /home/3yIyqh/prog.php on line 26
PHP Warning:  Invalid argument supplied for foreach() in /home/3yIyqh/prog.php on line 28
PHP Notice:  Undefined variable: clause in /home/3yIyqh/prog.php on line 39
PHP Warning:  implode(): Argument must be an array in /home/3yIyqh/prog.php on line 39