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][0],'{'); print_r($arr); echo substr($arr[0][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/I2Dmo
function name:  (null)
number of ops:  28
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        FETCH_DIM_R                                      ~12     ~11, 0
         12        SEND_VAL                                                 ~12
         13        SEND_VAL                                                 '%7B'
         14        DO_ICALL                                         $13     
         15        ASSIGN                                                   !5, $13
   19    16        INIT_FCALL                                               'print_r'
         17        SEND_VAR                                                 !4
         18        DO_ICALL                                                 
   20    19        INIT_FCALL                                               'substr'
         20        FETCH_DIM_R                                      ~16     !4, 0
         21        FETCH_DIM_R                                      ~17     ~16, 0
         22        SEND_VAL                                                 ~17
         23        SEND_VAL                                                 0
         24        SEND_VAR                                                 !5
         25        DO_ICALL                                         $18     
         26        ECHO                                                     $18
   29    27      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
159.57 ms | 1396 KiB | 21 Q