3v4l.org

run code in 300+ PHP versions simultaneously
<?php function stripEmptyTags ($result) { $regexps = array ( '~<(\w+)\b[^\>]*>([\s]|&nbsp;)*</\\1>~', '~<\w+\s*/>~', ); do { $string = $result; $result = preg_replace ($regexps, '', $string); } while ($result != $string); return $result; } function extractEmbedYT($str) { // Find all URLS in $str preg_match_all('/(\bhttps?:)?\/\/[^,\s()<>]+(?:\(\w+\)|(?:[^,[:punct:]\s]|\/))/s', $str, $matches); // Remove all iframes from $str $str = preg_replace('/<iframe.*?<\/iframe>/i','', $str); $str = stripEmptyTags($str); return [$str, $matches[0]]; } $string = '<p> </p><p>UDA Stagiaire</p><p><iframe width="560" height="315" src="//www.youtube.com/embed/PZlJFGgFTfA" frameborder="0" allowfullscreen=""></iframe></p>'; $results = extractEmbedYT($string); print_r($results);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/1OFDf
function name:  (null)
number of ops:  9
compiled vars:  !0 = $string, !1 = $results
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   ASSIGN                                                   !0, '%3Cp%3E%0A++%0A%3C%2Fp%3E%3Cp%3EUDA+Stagiaire%3C%2Fp%3E%3Cp%3E%3Ciframe+width%3D%22560%22+height%3D%22315%22+src%3D%22%2F%2Fwww.youtube.com%2Fembed%2FPZlJFGgFTfA%22+frameborder%3D%220%22+allowfullscreen%3D%22%22%3E%3C%2Fiframe%3E%3C%2Fp%3E'
   38     1        INIT_FCALL                                               'extractembedyt'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0  $3      
          4        ASSIGN                                                   !1, $3
   40     5        INIT_FCALL                                               'print_r'
          6        SEND_VAR                                                 !1
          7        DO_ICALL                                                 
          8      > RETURN                                                   1

Function stripemptytags:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 44) Position 1 = 11, Position 2 = 2
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 2
filename:       /in/1OFDf
function name:  stripEmptyTags
number of ops:  13
compiled vars:  !0 = $result, !1 = $regexps, !2 = $string
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    5     1        ASSIGN                                                   !1, <array>
   12     2    >   ASSIGN                                                   !2, !0
   13     3        INIT_FCALL                                               'preg_replace'
          4        SEND_VAR                                                 !1
          5        SEND_VAL                                                 ''
          6        SEND_VAR                                                 !2
          7        DO_ICALL                                         $5      
          8        ASSIGN                                                   !0, $5
   15     9        IS_NOT_EQUAL                                             !0, !2
         10      > JMPNZ                                                    ~7, ->2
   17    11    > > RETURN                                                   !0
   18    12*     > RETURN                                                   null

End of function stripemptytags

Function extractembedyt:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/1OFDf
function name:  extractEmbedYT
number of ops:  21
compiled vars:  !0 = $str, !1 = $matches
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   RECV                                             !0      
   24     1        INIT_FCALL                                               'preg_match_all'
          2        SEND_VAL                                                 '%2F%28%5Cbhttps%3F%3A%29%3F%5C%2F%5C%2F%5B%5E%2C%5Cs%28%29%3C%3E%5D%2B%28%3F%3A%5C%28%5Cw%2B%5C%29%7C%28%3F%3A%5B%5E%2C%5B%3Apunct%3A%5D%5Cs%5D%7C%5C%2F%29%29%2Fs'
          3        SEND_VAR                                                 !0
          4        SEND_REF                                                 !1
          5        DO_ICALL                                                 
   27     6        INIT_FCALL                                               'preg_replace'
          7        SEND_VAL                                                 '%2F%3Ciframe.%2A%3F%3C%5C%2Fiframe%3E%2Fi'
          8        SEND_VAL                                                 ''
          9        SEND_VAR                                                 !0
         10        DO_ICALL                                         $3      
         11        ASSIGN                                                   !0, $3
   30    12        INIT_FCALL                                               'stripemptytags'
         13        SEND_VAR                                                 !0
         14        DO_FCALL                                      0  $5      
         15        ASSIGN                                                   !0, $5
   31    16        INIT_ARRAY                                       ~7      !0
         17        FETCH_DIM_R                                      ~8      !1, 0
         18        ADD_ARRAY_ELEMENT                                ~7      ~8
         19      > RETURN                                                   ~7
   32    20*     > RETURN                                                   null

End of function extractembedyt

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
138.79 ms | 1007 KiB | 18 Q