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