fork download
  1. <?php
  2.  
  3.  
  4. $text0 = "ну что ???проверим-ка";
  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. $line = preg_replace('/\\s+/', " ", $line);
  34.  
  35. $punctuation_regexp = '/\\s*([,.!?]+)\\s*/u';
  36. $line = preg_replace($punctuation_regexp, "$1 ", $line);
  37.  
  38. $proper_lines[] = $line;
  39. }
  40.  
  41. $return = implode(". ", $proper_lines);
  42.  
  43. return $return;
  44. }
  45.  
  46. $fix0 = fixText($text0);
  47. $fix1 = fixText($text1);
  48. $fix2 = fixText($text2);
  49.  
  50. echo "$fix0\n$fix1\n$fix2";
Success #stdin #stdout 0.01s 20520KB
stdin
Standard input is empty
stdout
Ну что??? проверим-ка
Roses are red, and violets are blue. Whatever you do i'll keep it for you. 
Привет. Есть 2 функции!!??,, preg_split и explode, не понимаю, в чем?? между ними разница.