3v4l.org

run code in 300+ PHP versions simultaneously
<?php $rows = [ ['href' => 'https://www.php.net/', 'name' => 'PHP.net'], ['href' => 'https://stackoverflow.com/', 'name' => 'Stack Overflow'], ['href' => 'https://www.google.com/', 'name' => 'Google'] ]; $rows_by_href = array_reduce($rows, function ($rows_by_href, $row) { $rows_by_href[$row['href']] = $row['name']; return $rows_by_href; }, []); $string = "<a href='https://www.php.net/'>https://www.php.net/</a> <a href='https://stackoverflow.com/'>https://stackoverflow.com/</a> <a href='https://www.google.com/'>https://www.google.com/</a>"; $pattern = "/<a href='(?<href>.+?)'>(?<name>.+?)<\/a>/i"; $result = preg_replace_callback($pattern, function ($matches) use ($rows_by_href) { return "<a href='" . $matches['href'] . "'>" . ($rows_by_href[$matches['href']] ?? $matches['name']) . "</a>"; }, $string); echo $result;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/IY6p0
function name:  (null)
number of ops:  20
compiled vars:  !0 = $rows, !1 = $rows_by_href, !2 = $string, !3 = $pattern, !4 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
    8     1        INIT_FCALL                                               'array_reduce'
          2        SEND_VAR                                                 !0
          3        DECLARE_LAMBDA_FUNCTION                          ~6      [0]
   11     4        SEND_VAL                                                 ~6
          5        SEND_VAL                                                 <array>
    8     6        DO_ICALL                                         $7      
          7        ASSIGN                                                   !1, $7
   13     8        ASSIGN                                                   !2, '%3Ca+href%3D%27https%3A%2F%2Fwww.php.net%2F%27%3Ehttps%3A%2F%2Fwww.php.net%2F%3C%2Fa%3E+%0A%3Ca+href%3D%27https%3A%2F%2Fstackoverflow.com%2F%27%3Ehttps%3A%2F%2Fstackoverflow.com%2F%3C%2Fa%3E+%0A%3Ca+href%3D%27https%3A%2F%2Fwww.google.com%2F%27%3Ehttps%3A%2F%2Fwww.google.com%2F%3C%2Fa%3E'
   17     9        ASSIGN                                                   !3, '%2F%3Ca+href%3D%27%28%3F%3Chref%3E.%2B%3F%29%27%3E%28%3F%3Cname%3E.%2B%3F%29%3C%5C%2Fa%3E%2Fi'
   18    10        INIT_FCALL                                               'preg_replace_callback'
         11        SEND_VAR                                                 !3
         12        DECLARE_LAMBDA_FUNCTION                          ~11     [1]
         13        BIND_LEXICAL                                             ~11, !1
   20    14        SEND_VAL                                                 ~11
         15        SEND_VAR                                                 !2
   18    16        DO_ICALL                                         $12     
         17        ASSIGN                                                   !4, $12
   22    18        ECHO                                                     !4
   23    19      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/IY6p0
function name:  {closure}
number of ops:  8
compiled vars:  !0 = $rows_by_href, !1 = $row
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    9     2        FETCH_DIM_R                                      ~2      !1, 'href'
          3        FETCH_DIM_R                                      ~4      !1, 'name'
          4        ASSIGN_DIM                                               !0, ~2
          5        OP_DATA                                                  ~4
   10     6      > RETURN                                                   !0
   11     7*     > RETURN                                                   null

End of Dynamic Function 0

Dynamic Function 1
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/IY6p0
function name:  {closure}
number of ops:  14
compiled vars:  !0 = $matches, !1 = $rows_by_href
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   19     2        FETCH_DIM_R                                      ~2      !0, 'href'
          3        CONCAT                                           ~3      '%3Ca+href%3D%27', ~2
          4        CONCAT                                           ~4      ~3, '%27%3E'
          5        FETCH_DIM_R                                      ~5      !0, 'href'
          6        FETCH_DIM_IS                                     ~6      !1, ~5
          7        COALESCE                                         ~7      ~6
          8        FETCH_DIM_R                                      ~8      !0, 'name'
          9        QM_ASSIGN                                        ~7      ~8
         10        CONCAT                                           ~9      ~4, ~7
         11        CONCAT                                           ~10     ~9, '%3C%2Fa%3E'
         12      > RETURN                                                   ~10
   20    13*     > RETURN                                                   null

End of Dynamic Function 1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
144.01 ms | 1008 KiB | 15 Q