3v4l.org

run code in 500+ 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:  19
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                                                   'array_map'
          3        DECLARE_LAMBDA_FUNCTION                              ~4      [0]
          4        SEND_VAL                                                     ~4
          5        SEND_VAR                                                     !1
          6        DO_ICALL                                             $5      
          7        FRAMELESS_ICALL_2                implode             ~6      '%7C', $5
          8        CONCAT                                               ~7      '%2F%5Cb%28%3Fi%3A', ~6
          9        CONCAT                                               ~8      ~7, '%29%5Cb%5C.%3F%28%2ASKIP%29%28%2AFAIL%29%7C%5C.%5Cs%2A%5Cp%7BLl%7D%2Fu'
         10        ASSIGN                                                       !2, ~8
    6    11        INIT_FCALL                                                   'preg_replace_callback'
    7    12        SEND_VAR                                                     !2
    8    13        DECLARE_LAMBDA_FUNCTION                              ~10     [1]
   10    14        SEND_VAL                                                     ~10
         15        SEND_VAR                                                     !0
    6    16        DO_ICALL                                             $11     
   10    17        ECHO                                                         $11
   11    18      > RETURN                                                       null


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

End of Dynamic Function 0

Dynamic Function 1
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/rsX8r
function name:  {closure:upper_letter():8}
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 Dynamic Function 1

End of function upper_letter

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
150.89 ms | 1584 KiB | 14 Q