3v4l.org

run code in 300+ PHP versions simultaneously
<?php error_reporting(-1); mb_internal_encoding('utf-8'); $text = "много их в Петербурге,молоденьких дур,сегодня в атласе да бархате,а завтра , поглядишь , метут улицу вместе с голью кабацкою...в самом деле ,что было бы с нами ,если бы вместо общеудобного правила:чин чина почитай , ввелось в употребление другое,например:ум ума почитай?какие возникли бы споры!"; //$text = "ну что. не смотрел еще black mesa.я собирался скачать ,но все как-то некогда было."; // Для тестов //$text = "roses are red,and violets are blue.whatever you do i'll keep it for you."; //$text = "привет.есть 2 функции,preg_split и explode ,не понимаю,в чем между ними разница."; /* Делает первую букву в строке заглавной */ function makeFirstLetterUppercase($text) { $second = 1; $first = mb_substr($text, 0, $second); //проверяем, чтобы первый символ был не пробелом{ if ($first == ' '){ $second = 2; $first = mb_substr($text, 0, $second); } //} $other = mb_substr($text, $second); $first = mb_strtoupper($first); $text = $first . $other; return $text; } /* исправляет текст */ function fixText($text) { //$text = makeFirstLetterUppercase($text); //убрали лишние пробелы{ $regexp = '/ + /u'; $text = preg_replace($regexp, ' ', $text); //} //ставим пробел после знака препинания{ $regexp = '/([\\.,;:!\\?])(\w)/u'; $text = preg_replace($regexp, '$1 $2', $text); //} //убираем пробелы перед знаками препинания{ $regexp = '/(\w)( )([\\.,;:!\\?])/u'; $text = preg_replace($regexp, '$1$3', $text); //} //разбиваем исходный текст на предложения //и ставим заглавные буквы{ $regexp = '/(?<=[\\.!\\?])/u'; $parts = preg_split($regexp, $text, 0, PREG_SPLIT_NO_EMPTY); $text = ""; foreach ($parts as $part){ $text = $text . makeFirstLetterUppercase($part); } //} return $text; } $result = fixText($text); echo "{$result}\n";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RpEMF
function name:  (null)
number of ops:  15
compiled vars:  !0 = $text, !1 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                               'error_reporting'
          1        SEND_VAL                                                 -1
          2        DO_ICALL                                                 
    4     3        INIT_FCALL                                               'mb_internal_encoding'
          4        SEND_VAL                                                 'utf-8'
          5        DO_ICALL                                                 
    6     6        ASSIGN                                                   !0, '%D0%BC%D0%BD%D0%BE%D0%B3%D0%BE+%D0%B8%D1%85+%D0%B2+%D0%9F%D0%B5%D1%82%D0%B5%D1%80%D0%B1%D1%83%D1%80%D0%B3%D0%B5%2C%D0%BC%D0%BE%D0%BB%D0%BE%D0%B4%D0%B5%D0%BD%D1%8C%D0%BA%D0%B8%D1%85+%D0%B4%D1%83%D1%80%2C%D1%81%D0%B5%D0%B3%D0%BE%D0%B4%D0%BD%D1%8F+%D0%B2+%D0%B0%D1%82%D0%BB%D0%B0%D1%81%D0%B5+%D0%B4%D0%B0+%D0%B1%D0%B0%D1%80%D1%85%D0%B0%D1%82%D0%B5%2C%D0%B0+%D0%B7%D0%B0%D0%B2%D1%82%D1%80%D0%B0+%2C+%D0%BF%D0%BE%D0%B3%D0%BB%D1%8F%D0%B4%D0%B8%D1%88%D1%8C+%2C+%D0%BC%D0%B5%D1%82%D1%83%D1%82+%D1%83%D0%BB%D0%B8%D1%86%D1%83+%D0%B2%D0%BC%D0%B5%D1%81%D1%82%D0%B5+%D1%81+%D0%B3%D0%BE%D0%BB%D1%8C%D1%8E+%D0%BA%D0%B0%D0%B1%D0%B0%D1%86%D0%BA%D0%BE%D1%8E...%D0%B2+%D1%81%D0%B0%D0%BC%D0%BE%D0%BC+%D0%B4%D0%B5%D0%BB%D0%B5+%2C%D1%87%D1%82%D0%BE+%D0%B1%D1%8B%D0%BB%D0%BE+%D0%B1%D1%8B+%D1%81+%D0%BD%D0%B0%D0%BC%D0%B8+%2C%D0%B5%D1%81%D0%BB%D0%B8+%D0%B1%D1%8B+%D0%B2%D0%BC%D0%B5%D1%81%D1%82%D0%BE+%D0%BE%D0%B1%D1%89%D0%B5%D1%83%D0%B4%D0%BE%D0%B1%D0%BD%D0%BE%D0%B3%D0%BE+%D0%BF%D1%80%D0%B0%D0%B2%D0%B8%D0%BB%D0%B0%3A%D1%87%D0%B8%D0%BD+%D1%87%D0%B8%D0%BD%D0%B0+%D0%BF%D0%BE%D1%87%D0%B8%D1%82%D0%B0%D0%B9+%2C+%D0%B2%D0%B2%D0%B5%D0%BB%D0%BE%D1%81%D1%8C+%D0%B2+%D1%83%D0%BF%D0%BE%D1%82%D1%80%D0%B5%D0%B1%D0%BB%D0%B5%D0%BD%D0%B8%D0%B5+%D0%B4%D1%80%D1%83%D0%B3%D0%BE%D0%B5%2C%D0%BD%D0%B0%D0%BF%D1%80%D0%B8%D0%BC%D0%B5%D1%80%3A%D1%83%D0%BC+%D1%83%D0%BC%D0%B0+%D0%BF%D0%BE%D1%87%D0%B8%D1%82%D0%B0%D0%B9%3F%D0%BA%D0%B0%D0%BA%D0%B8%D0%B5+%D0%B2%D0%BE%D0%B7%D0%BD%D0%B8%D0%BA%D0%BB%D0%B8+%D0%B1%D1%8B+%D1%81%D0%BF%D0%BE%D1%80%D1%8B%21'
   56     7        INIT_FCALL                                               'fixtext'
          8        SEND_VAR                                                 !0
          9        DO_FCALL                                      0  $5      
         10        ASSIGN                                                   !1, $5
   57    11        NOP                                                      
         12        FAST_CONCAT                                      ~7      !1, '%0A'
         13        ECHO                                                     ~7
         14      > RETURN                                                   1

Function makefirstletteruppercase:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 17
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
filename:       /in/RpEMF
function name:  makeFirstLetterUppercase
number of ops:  30
compiled vars:  !0 = $text, !1 = $second, !2 = $first, !3 = $other
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
   14     1        ASSIGN                                                   !1, 1
   15     2        INIT_FCALL                                               'mb_substr'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 0
          5        SEND_VAR                                                 !1
          6        DO_ICALL                                         $5      
          7        ASSIGN                                                   !2, $5
   17     8        IS_EQUAL                                                 !2, '+'
          9      > JMPZ                                                     ~7, ->17
   18    10    >   ASSIGN                                                   !1, 2
   19    11        INIT_FCALL                                               'mb_substr'
         12        SEND_VAR                                                 !0
         13        SEND_VAL                                                 0
         14        SEND_VAR                                                 !1
         15        DO_ICALL                                         $9      
         16        ASSIGN                                                   !2, $9
   22    17    >   INIT_FCALL                                               'mb_substr'
         18        SEND_VAR                                                 !0
         19        SEND_VAR                                                 !1
         20        DO_ICALL                                         $11     
         21        ASSIGN                                                   !3, $11
   23    22        INIT_FCALL                                               'mb_strtoupper'
         23        SEND_VAR                                                 !2
         24        DO_ICALL                                         $13     
         25        ASSIGN                                                   !2, $13
   24    26        CONCAT                                           ~15     !2, !3
         27        ASSIGN                                                   !0, ~15
   25    28      > RETURN                                                   !0
   26    29*     > RETURN                                                   null

End of function makefirstletteruppercase

Function fixtext:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 32, Position 2 = 39
Branch analysis from position: 32
2 jumps found. (Code = 78) Position 1 = 33, Position 2 = 39
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
Branch analysis from position: 39
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 39
filename:       /in/RpEMF
function name:  fixText
number of ops:  42
compiled vars:  !0 = $text, !1 = $regexp, !2 = $parts, !3 = $part
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   RECV                                             !0      
   32     1        ASSIGN                                                   !1, '%2F+%2B+%2Fu'
   33     2        INIT_FCALL                                               'preg_replace'
          3        SEND_VAR                                                 !1
          4        SEND_VAL                                                 '+'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $5      
          7        ASSIGN                                                   !0, $5
   36     8        ASSIGN                                                   !1, '%2F%28%5B%5C.%2C%3B%3A%21%5C%3F%5D%29%28%5Cw%29%2Fu'
   37     9        INIT_FCALL                                               'preg_replace'
         10        SEND_VAR                                                 !1
         11        SEND_VAL                                                 '%241+%242'
         12        SEND_VAR                                                 !0
         13        DO_ICALL                                         $8      
         14        ASSIGN                                                   !0, $8
   40    15        ASSIGN                                                   !1, '%2F%28%5Cw%29%28+%29%28%5B%5C.%2C%3B%3A%21%5C%3F%5D%29%2Fu'
   41    16        INIT_FCALL                                               'preg_replace'
         17        SEND_VAR                                                 !1
         18        SEND_VAL                                                 '%241%243'
         19        SEND_VAR                                                 !0
         20        DO_ICALL                                         $11     
         21        ASSIGN                                                   !0, $11
   45    22        ASSIGN                                                   !1, '%2F%28%3F%3C%3D%5B%5C.%21%5C%3F%5D%29%2Fu'
   46    23        INIT_FCALL                                               'preg_split'
         24        SEND_VAR                                                 !1
         25        SEND_VAR                                                 !0
         26        SEND_VAL                                                 0
         27        SEND_VAL                                                 1
         28        DO_ICALL                                         $14     
         29        ASSIGN                                                   !2, $14
   47    30        ASSIGN                                                   !0, ''
   48    31      > FE_RESET_R                                       $17     !2, ->39
         32    > > FE_FETCH_R                                               $17, !3, ->39
   49    33    >   INIT_FCALL                                               'makefirstletteruppercase'
         34        SEND_VAR                                                 !3
         35        DO_FCALL                                      0  $18     
         36        CONCAT                                           ~19     !0, $18
         37        ASSIGN                                                   !0, ~19
   48    38      > JMP                                                      ->32
         39    >   FE_FREE                                                  $17
   52    40      > RETURN                                                   !0
   54    41*     > RETURN                                                   null

End of function fixtext

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
172.89 ms | 1407 KiB | 27 Q