3v4l.org

run code in 300+ PHP versions simultaneously
<?php $replacement = 'NEW TEXT'; $htmlContent = <<<HTML <p data-edit="1">TEXT A</p> <div not-data-edit="2">TEXT C</div> <div data-edit="2">TEXT B</div> HTML; $targetNumber = 2; $pattern = '#<(p|div|any other tag)[^>]* data-edit="' . preg_quote($targetNumber) . '"[^>]*>\K.*?(?=</\1>)#is'; echo preg_replace($pattern, $replacement, $htmlContent);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/oDGN2
function name:  (null)
number of ops:  16
compiled vars:  !0 = $replacement, !1 = $htmlContent, !2 = $targetNumber, !3 = $pattern
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, 'NEW+TEXT'
    4     1        ASSIGN                                                   !1, '%3Cp+data-edit%3D%221%22%3ETEXT+A%3C%2Fp%3E%0A%3Cdiv+not-data-edit%3D%222%22%3ETEXT+C%3C%2Fdiv%3E%0A%3Cdiv+data-edit%3D%222%22%3ETEXT+B%3C%2Fdiv%3E'
   10     2        ASSIGN                                                   !2, 2
   12     3        INIT_FCALL                                               'preg_quote'
          4        SEND_VAR                                                 !2
          5        DO_ICALL                                         $7      
          6        CONCAT                                           ~8      '%23%3C%28p%7Cdiv%7Cany+other+tag%29%5B%5E%3E%5D%2A+data-edit%3D%22', $7
          7        CONCAT                                           ~9      ~8, '%22%5B%5E%3E%5D%2A%3E%5CK.%2A%3F%28%3F%3D%3C%2F%5C1%3E%29%23is'
          8        ASSIGN                                                   !3, ~9
   14     9        INIT_FCALL                                               'preg_replace'
         10        SEND_VAR                                                 !3
         11        SEND_VAR                                                 !0
         12        SEND_VAR                                                 !1
         13        DO_ICALL                                         $11     
         14        ECHO                                                     $11
         15      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
141.7 ms | 1010 KiB | 15 Q