3v4l.org

run code in 300+ PHP versions simultaneously
<?php // 1. Identify the block of <a> elements $string = '<div><a href=%http://link1%><img></a><a href=%http://link2%><img></a><a href=%http://link3%><img></a></div>'; $re = '|<div>((<a((?!href)(?!<).)+?href=%([^%]+?)%((?!</a>).)+?</a>){3})</div>|'; $matches = array(); echo('result='.intval(preg_match($re, $string, $matches))."\n"); echo('$matches='); print_r($matches); // 2. Split it into individual <a> elements $re = '|(?<=</a>)(?=<a)|'; $pieces = preg_split($re, $matches[1]); echo('$pieces='); print_r($pieces); // 3. Analyze each <a> element, extract the interesting components $re = '|href=%([^%]*)%|'; foreach ($pieces as $a) { $matches = array(); if (preg_match($re, $a, $matches)) { echo($a.': '.$matches[1]."\n"); } }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 29, Position 2 = 43
Branch analysis from position: 29
2 jumps found. (Code = 78) Position 1 = 30, Position 2 = 43
Branch analysis from position: 30
2 jumps found. (Code = 43) Position 1 = 37, Position 2 = 42
Branch analysis from position: 37
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
Branch analysis from position: 42
Branch analysis from position: 43
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 43
filename:       /in/OMtFn
function name:  (null)
number of ops:  45
compiled vars:  !0 = $string, !1 = $re, !2 = $matches, !3 = $pieces, !4 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%3Cdiv%3E%3Ca+href%3D%25http%3A%2F%2Flink1%25%3E%3Cimg%3E%3C%2Fa%3E%3Ca+href%3D%25http%3A%2F%2Flink2%25%3E%3Cimg%3E%3C%2Fa%3E%3Ca+href%3D%25http%3A%2F%2Flink3%25%3E%3Cimg%3E%3C%2Fa%3E%3C%2Fdiv%3E'
    4     1        ASSIGN                                                   !1, '%7C%3Cdiv%3E%28%28%3Ca%28%28%3F%21href%29%28%3F%21%3C%29.%29%2B%3Fhref%3D%25%28%5B%5E%25%5D%2B%3F%29%25%28%28%3F%21%3C%2Fa%3E%29.%29%2B%3F%3C%2Fa%3E%29%7B3%7D%29%3C%2Fdiv%3E%7C'
    5     2        ASSIGN                                                   !2, <array>
    7     3        INIT_FCALL                                               'preg_match'
          4        SEND_VAR                                                 !1
          5        SEND_VAR                                                 !0
          6        SEND_REF                                                 !2
          7        DO_ICALL                                         $8      
          8        CAST                                          4  ~9      $8
          9        CONCAT                                           ~10     'result%3D', ~9
         10        CONCAT                                           ~11     ~10, '%0A'
         11        ECHO                                                     ~11
    8    12        ECHO                                                     '%24matches%3D'
         13        INIT_FCALL                                               'print_r'
         14        SEND_VAR                                                 !2
         15        DO_ICALL                                                 
   11    16        ASSIGN                                                   !1, '%7C%28%3F%3C%3D%3C%2Fa%3E%29%28%3F%3D%3Ca%29%7C'
   12    17        INIT_FCALL                                               'preg_split'
         18        SEND_VAR                                                 !1
         19        FETCH_DIM_R                                      ~14     !2, 1
         20        SEND_VAL                                                 ~14
         21        DO_ICALL                                         $15     
         22        ASSIGN                                                   !3, $15
   13    23        ECHO                                                     '%24pieces%3D'
         24        INIT_FCALL                                               'print_r'
         25        SEND_VAR                                                 !3
         26        DO_ICALL                                                 
   16    27        ASSIGN                                                   !1, '%7Chref%3D%25%28%5B%5E%25%5D%2A%29%25%7C'
   17    28      > FE_RESET_R                                       $19     !3, ->43
         29    > > FE_FETCH_R                                               $19, !4, ->43
   18    30    >   ASSIGN                                                   !2, <array>
   19    31        INIT_FCALL                                               'preg_match'
         32        SEND_VAR                                                 !1
         33        SEND_VAR                                                 !4
         34        SEND_REF                                                 !2
         35        DO_ICALL                                         $21     
         36      > JMPZ                                                     $21, ->42
   20    37    >   CONCAT                                           ~22     !4, '%3A+'
         38        FETCH_DIM_R                                      ~23     !2, 1
         39        CONCAT                                           ~24     ~22, ~23
         40        CONCAT                                           ~25     ~24, '%0A'
         41        ECHO                                                     ~25
   17    42    > > JMP                                                      ->29
         43    >   FE_FREE                                                  $19
   22    44      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.02 ms | 1400 KiB | 19 Q