3v4l.org

run code in 300+ PHP versions simultaneously
<?php $exp = '/[\s\S]*\{%[\s\S]*for[\s\S]*ad[\s\S]*in[\s\S]*ads[\s\S]*%\}/'; $string = "{% for ad in ads %} sdfksjf {% for ad in ads %} sdfksjf2 {% for ad in ads %} sdfksjf3"; /* function str_lreplace($search, $replace, $subject) { return preg_replace('~(.*)' . preg_quote($search, '~') . '~', '$1' . $replace, $subject, 1); } echo str_lreplace($exp,'',$string); */ $end_loop_regex = '/[\.\s\S]*\{%[\s\S]*endfor[\s\S]*%\}/'; $endfor_str = "{% endfor%}1 {% endfor %}2 {%endfor%}3 {% endfor%}4"; //$arr = preg_split($end_loop_regex,$endfor_str,0,PREG_SPLIT_OFFSET_CAPTURE); preg_match($end_loop_regex,$endfor_str,$arr); //$string = $arr[0][0][0]; $start_tag = strrpos($arr[0],'{'); print_r($arr); echo substr($arr[0],0,$start_tag); //$last_end_for_pos = strrpos($return,'{% endfor %}'); //$return = substr($return,0,$last_end_for_pos);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/119gF
function name:  (null)
number of ops:  26
compiled vars:  !0 = $exp, !1 = $string, !2 = $end_loop_regex, !3 = $endfor_str, !4 = $arr, !5 = $start_tag
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, '%2F%5B%5Cs%5CS%5D%2A%5C%7B%25%5B%5Cs%5CS%5D%2Afor%5B%5Cs%5CS%5D%2Aad%5B%5Cs%5CS%5D%2Ain%5B%5Cs%5CS%5D%2Aads%5B%5Cs%5CS%5D%2A%25%5C%7D%2F'
    3     1        ASSIGN                                                   !1, '%7B%25+for+ad+in+ads+%25%7D+sdfksjf++%7B%25+for+ad+in+ads+%25%7D+sdfksjf2+%7B%25+for+ad+in+ads+%25%7D+sdfksjf3'
   12     2        ASSIGN                                                   !2, '%2F%5B%5C.%5Cs%5CS%5D%2A%5C%7B%25%5B%5Cs%5CS%5D%2Aendfor%5B%5Cs%5CS%5D%2A%25%5C%7D%2F'
   13     3        ASSIGN                                                   !3, '%7B%25+endfor%25%7D1+%7B%25+endfor+%25%7D2+%7B%25endfor%25%7D3+%7B%25+endfor%25%7D4'
   16     4        INIT_FCALL                                               'preg_match'
          5        SEND_VAR                                                 !2
          6        SEND_VAR                                                 !3
          7        SEND_REF                                                 !4
          8        DO_ICALL                                                 
   18     9        INIT_FCALL                                               'strrpos'
         10        FETCH_DIM_R                                      ~11     !4, 0
         11        SEND_VAL                                                 ~11
         12        SEND_VAL                                                 '%7B'
         13        DO_ICALL                                         $12     
         14        ASSIGN                                                   !5, $12
   19    15        INIT_FCALL                                               'print_r'
         16        SEND_VAR                                                 !4
         17        DO_ICALL                                                 
   20    18        INIT_FCALL                                               'substr'
         19        FETCH_DIM_R                                      ~15     !4, 0
         20        SEND_VAL                                                 ~15
         21        SEND_VAL                                                 0
         22        SEND_VAR                                                 !5
         23        DO_ICALL                                         $16     
         24        ECHO                                                     $16
   29    25      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.15 ms | 1387 KiB | 21 Q