3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html_string = '<!DOCTYPE html> <html> <body> <div id="foo"> This is a paragraph with <strong>Some nested tags</strong> </div> <div class="test" id="bar"> <div> And a nested div? </div> </div> <div class="baz test"> <p> Pretty normal HTML. </p> </div> </body> </html>'; $regex = '/<div[^>]*?(class="(.+?)"[^>]*)?>((?:.*?(?:(?!<div)|(?R))*)*)' . '<\/div>/sm'; if (preg_match_all($regex, $html_string, $matches, PREG_SET_ORDER)) { foreach ($matches as $match) { if (in_array('test', explode(' ', $match[2]))) { echo trim ($matches[4]); } } }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 28
Branch analysis from position: 9
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 27
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 27
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 26
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 26
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
Branch analysis from position: 28
filename:       /in/7asgj
function name:  (null)
number of ops:  29
compiled vars:  !0 = $html_string, !1 = $regex, !2 = $matches, !3 = $match
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%3C%21DOCTYPE+html%3E%0A%3Chtml%3E%0A%09%3Cbody%3E%0A%09%09%3Cdiv+id%3D%22foo%22%3E%0A%09%09%09This+is+a+paragraph+with%0A%09%09%09%3Cstrong%3ESome+nested+tags%3C%2Fstrong%3E%0A%09%09%3C%2Fdiv%3E%0A%0A%09%09%3Cdiv+class%3D%22test%22+id%3D%22bar%22%3E%0A%09%09%09%3Cdiv%3E%0A%09%09%09%09And+a+nested+div%3F%0A%09%09%09%3C%2Fdiv%3E%0A%09%09%3C%2Fdiv%3E%0A%0A%09%09%3Cdiv+class%3D%22baz+test%22%3E%0A%09%09%09%3Cp%3E%0A%09%09%09%09Pretty+normal+HTML.%0A%09%09%09%3C%2Fp%3E%0A%09%09%3C%2Fdiv%3E%0A%09%3C%2Fbody%3E%0A%3C%2Fhtml%3E'
   25     1        ASSIGN                                                   !1, '%2F%3Cdiv%5B%5E%3E%5D%2A%3F%28class%3D%22%28.%2B%3F%29%22%5B%5E%3E%5D%2A%29%3F%3E%28%28%3F%3A.%2A%3F%28%3F%3A%28%3F%21%3Cdiv%29%7C%28%3FR%29%29%2A%29%2A%29%3C%5C%2Fdiv%3E%2Fsm'
   28     2        INIT_FCALL                                               'preg_match_all'
          3        SEND_VAR                                                 !1
          4        SEND_VAR                                                 !0
          5        SEND_REF                                                 !2
          6        SEND_VAL                                                 2
          7        DO_ICALL                                         $6      
          8      > JMPZ                                                     $6, ->28
   29     9    > > FE_RESET_R                                       $7      !2, ->27
         10    > > FE_FETCH_R                                               $7, !3, ->27
   30    11    >   INIT_FCALL                                               'in_array'
         12        SEND_VAL                                                 'test'
         13        INIT_FCALL                                               'explode'
         14        SEND_VAL                                                 '+'
         15        FETCH_DIM_R                                      ~8      !3, 2
         16        SEND_VAL                                                 ~8
         17        DO_ICALL                                         $9      
         18        SEND_VAR                                                 $9
         19        DO_ICALL                                         $10     
         20      > JMPZ                                                     $10, ->26
   31    21    >   INIT_FCALL                                               'trim'
         22        FETCH_DIM_R                                      ~11     !2, 4
         23        SEND_VAL                                                 ~11
         24        DO_ICALL                                         $12     
         25        ECHO                                                     $12
   29    26    > > JMP                                                      ->10
         27    >   FE_FREE                                                  $7
   34    28    > > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
162.68 ms | 1396 KiB | 21 Q