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. Extract the URLs $re = '|<a((?!href)(?!<).)+?href=%([^%]+?)%((?!</a>).)+?</a>|'; preg_match_all($re, $matches[1], $matches); echo('URLs='); print_r($matches[2]);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/K4mLR
function name:  (null)
number of ops:  29
compiled vars:  !0 = $string, !1 = $re, !2 = $matches
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                                         $6      
          8        CAST                                          4  ~7      $6
          9        CONCAT                                           ~8      'result%3D', ~7
         10        CONCAT                                           ~9      ~8, '%0A'
         11        ECHO                                                     ~9
    8    12        ECHO                                                     '%24matches%3D'
         13        INIT_FCALL                                               'print_r'
         14        SEND_VAR                                                 !2
         15        DO_ICALL                                                 
   11    16        ASSIGN                                                   !1, '%7C%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%7C'
   12    17        INIT_FCALL                                               'preg_match_all'
         18        SEND_VAR                                                 !1
         19        FETCH_DIM_R                                      ~12     !2, 1
         20        SEND_VAL                                                 ~12
         21        SEND_REF                                                 !2
         22        DO_ICALL                                                 
   13    23        ECHO                                                     'URLs%3D'
         24        INIT_FCALL                                               'print_r'
         25        FETCH_DIM_R                                      ~14     !2, 2
         26        SEND_VAL                                                 ~14
         27        DO_ICALL                                                 
         28      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
169.8 ms | 1388 KiB | 19 Q