3v4l.org

run code in 300+ PHP versions simultaneously
<?php function upper_letter($text){ $exp = ['т.д','т.п','др','г','чел','пр', 'см']; $pattern = '/\b(?i:' . implode("|", array_map(function($i) { return preg_quote(trim($i), "/"); }, $exp)) . ')\b\.?(*SKIP)(*FAIL)|\.\s*\p{Ll}/u'; // добавляем модификатор u, чтобы регулярка работала с многобайтными кодировками (utf-8, utf-16) echo preg_replace_callback( $pattern, function($m) { // на вход поступает каждое из найденных соответствий return mb_strtoupper($m[0]); // используем mb_ функцию, так как она работает с многобайтными кодировками }, $text); } upper_letter('Я охотник. живу в лесу.и мне комфортно и т.п'); echo PHP_EOL; upper_letter('См. тут. я читал и др. произведения. в 2003 г. никто об этом не знал. и т.д. и т.п');
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/rsX8r
function name:  (null)
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   INIT_FCALL                                               'upper_letter'
          1        SEND_VAL                                                 '%D0%AF+%D0%BE%D1%85%D0%BE%D1%82%D0%BD%D0%B8%D0%BA.+%D0%B6%D0%B8%D0%B2%D1%83+%D0%B2+%D0%BB%D0%B5%D1%81%D1%83.%D0%B8+%D0%BC%D0%BD%D0%B5+%D0%BA%D0%BE%D0%BC%D1%84%D0%BE%D1%80%D1%82%D0%BD%D0%BE+%D0%B8+%D1%82.%D0%BF'
          2        DO_FCALL                                      0          
          3        ECHO                                                     '%0A'
   14     4        INIT_FCALL                                               'upper_letter'
          5        SEND_VAL                                                 '%D0%A1%D0%BC.+%D1%82%D1%83%D1%82.+%D1%8F+%D1%87%D0%B8%D1%82%D0%B0%D0%BB+%D0%B8+%D0%B4%D1%80.+%D0%BF%D1%80%D0%BE%D0%B8%D0%B7%D0%B2%D0%B5%D0%B4%D0%B5%D0%BD%D0%B8%D1%8F.+%D0%B2+2003+%D0%B3.+%D0%BD%D0%B8%D0%BA%D1%82%D0%BE+%D0%BE%D0%B1+%D1%8D%D1%82%D0%BE%D0%BC+%D0%BD%D0%B5+%D0%B7%D0%BD%D0%B0%D0%BB.+%D0%B8+%D1%82.%D0%B4.+%D0%B8+%D1%82.%D0%BF'
          6        DO_FCALL                                      0          
          7      > RETURN                                                   1

Function upper_letter:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/rsX8r
function name:  upper_letter
number of ops:  22
compiled vars:  !0 = $text, !1 = $exp, !2 = $pattern
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        ASSIGN                                                   !1, <array>
    5     2        INIT_FCALL                                               'implode'
          3        SEND_VAL                                                 '%7C'
          4        INIT_FCALL                                               'array_map'
          5        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FrsX8r%3A5%240'
          6        SEND_VAL                                                 ~4
          7        SEND_VAR                                                 !1
          8        DO_ICALL                                         $5      
          9        SEND_VAR                                                 $5
         10        DO_ICALL                                         $6      
         11        CONCAT                                           ~7      '%2F%5Cb%28%3Fi%3A', $6
         12        CONCAT                                           ~8      ~7, '%29%5Cb%5C.%3F%28%2ASKIP%29%28%2AFAIL%29%7C%5C.%5Cs%2A%5Cp%7BLl%7D%2Fu'
         13        ASSIGN                                                   !2, ~8
    6    14        INIT_FCALL                                               'preg_replace_callback'
    7    15        SEND_VAR                                                 !2
    8    16        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FrsX8r%3A8%241'
   10    17        SEND_VAL                                                 ~10
         18        SEND_VAR                                                 !0
         19        DO_ICALL                                         $11     
         20        ECHO                                                     $11
   11    21      > RETURN                                                   null

End of function upper_letter

Function %00%7Bclosure%7D%2Fin%2FrsX8r%3A5%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/rsX8r
function name:  {closure}
number of ops:  10
compiled vars:  !0 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
          1        INIT_FCALL                                               'preg_quote'
          2        INIT_FCALL                                               'trim'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $1      
          5        SEND_VAR                                                 $1
          6        SEND_VAL                                                 '%2F'
          7        DO_ICALL                                         $2      
          8      > RETURN                                                   $2
          9*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FrsX8r%3A5%240

Function %00%7Bclosure%7D%2Fin%2FrsX8r%3A8%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/rsX8r
function name:  {closure}
number of ops:  7
compiled vars:  !0 = $m
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
    9     1        INIT_FCALL                                               'mb_strtoupper'
          2        FETCH_DIM_R                                      ~1      !0, 0
          3        SEND_VAL                                                 ~1
          4        DO_ICALL                                         $2      
          5      > RETURN                                                   $2
   10     6*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FrsX8r%3A8%241

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
187.05 ms | 1403 KiB | 27 Q