fork download
  1. <?php
  2.  
  3.  
  4. $text0 = "ну что??? не смотрел еще black mesa.я собирался скачать ,но все как-то некогда было.";
  5. $text1 = 'roses are red,and violets are blue.whatever you do i\'ll keep it for you.';
  6. $text2 = 'привет.есть 2 функции,preg_split и explode ,не понимаю,в чем между ними разница.';
  7.  
  8. function mb_ucfirst ($subj)
  9. {
  10. $subj_length = mb_strlen($subj);
  11.  
  12. $subj_first = mb_substr($subj, 0, 1);
  13. $subj_other = mb_substr($subj, 1, $subj_length);
  14.  
  15. $subj_first_uc = mb_strtoupper($subj_first);
  16. $subj_other_lc = mb_strtolower($subj_other);
  17.  
  18. $subj_ucased =$subj_first_uc.$subj_other_lc;
  19.  
  20. return $subj_ucased;
  21. }
  22. function fixText ($text)
  23. {
  24. $split_regexp = '/\\./';
  25. $raw_lines = preg_split($split_regexp, $text);
  26.  
  27. $proper_lines = array();
  28.  
  29. foreach ($raw_lines as $line) {
  30. $line = trim($line);
  31. $line = mb_ucfirst($line);
  32.  
  33. $spaces_regexp = '/\\s\\s+/';
  34. $line = preg_replace($spaces_regexp, " ", $line);
  35.  
  36. $punctuation_before_regexp = '/(?:\\s([,.!?]))/u';
  37. $line = preg_replace($punctuation_before_regexp, "$1 ", $line);
  38.  
  39. $punctiation_after_regexp = '/([,.!?])([^\\s])/';
  40. $line = preg_replace($punctiation_after_regexp, "$1 $2", $line);
  41. $proper_lines[] = $line;
  42. }
  43.  
  44. $return = implode(". ", $proper_lines);
  45.  
  46. return $return;
  47. }
  48.  
  49. $fix0 = fixText($text0);
  50. $fix1 = fixText($text1);
  51. $fix2 = fixText($text2);
  52.  
  53. echo "$fix0\n$fix1\n$fix2";
Success #stdin #stdout 0.01s 20568KB
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, не понимаю, в чем между ними разница.