3v4l.org

run code in 300+ PHP versions simultaneously
<?php function check_link($link) { if(preg_match("#(?<=v=)[a-zA-Z0-9-]+(?=&)|(?<=v\/)[^&\n]+(?=\?)|(?<=v=)[^&\n]+|(?<=youtu.be/)[^&\n]+#", $link, $r)) { $pattern = '#<a\s?href="(https?:\/\/(?:www.)?[\w.\#\/?=]+)">\1<\/a>#is'; return preg_replace($pattern,'<iframe width="560" height="315" src="https://www.youtube.com/embed/'.$r[0].'" frameborder="0"></iframe>',$link); } } echo check_link('<a href="https://www.youtube.com/watch?v=Z7Oc8QaM5VU">https://www.youtube.com/watch?v=Z7Oc8QaM5VU</a>');
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kY1eb
function name:  (null)
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   INIT_FCALL                                               'check_link'
          1        SEND_VAL                                                 '%3Ca+href%3D%22https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DZ7Oc8QaM5VU%22%3Ehttps%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DZ7Oc8QaM5VU%3C%2Fa%3E'
          2        DO_FCALL                                      0  $0      
          3        ECHO                                                     $0
          4      > RETURN                                                   1

Function check_link:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 17
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kY1eb
function name:  check_link
number of ops:  18
compiled vars:  !0 = $link, !1 = $r, !2 = $pattern
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
    4     1        INIT_FCALL                                               'preg_match'
          2        SEND_VAL                                                 '%23%28%3F%3C%3Dv%3D%29%5Ba-zA-Z0-9-%5D%2B%28%3F%3D%26%29%7C%28%3F%3C%3Dv%5C%2F%29%5B%5E%26%0A%5D%2B%28%3F%3D%5C%3F%29%7C%28%3F%3C%3Dv%3D%29%5B%5E%26%0A%5D%2B%7C%28%3F%3C%3Dyoutu.be%2F%29%5B%5E%26%0A%5D%2B%23'
          3        SEND_VAR                                                 !0
          4        SEND_REF                                                 !1
          5        DO_ICALL                                         $3      
          6      > JMPZ                                                     $3, ->17
    6     7    >   ASSIGN                                                   !2, '%23%3Ca%5Cs%3Fhref%3D%22%28https%3F%3A%5C%2F%5C%2F%28%3F%3Awww.%29%3F%5B%5Cw.%5C%23%5C%2F%3F%3D%5D%2B%29%22%3E%5C1%3C%5C%2Fa%3E%23is'
    7     8        INIT_FCALL                                               'preg_replace'
          9        SEND_VAR                                                 !2
         10        FETCH_DIM_R                                      ~5      !1, 0
         11        CONCAT                                           ~6      '%3Ciframe+width%3D%22560%22+height%3D%22315%22+src%3D%22https%3A%2F%2Fwww.youtube.com%2Fembed%2F', ~5
         12        CONCAT                                           ~7      ~6, '%22+frameborder%3D%220%22%3E%3C%2Fiframe%3E'
         13        SEND_VAL                                                 ~7
         14        SEND_VAR                                                 !0
         15        DO_ICALL                                         $8      
         16      > RETURN                                                   $8
    9    17    > > RETURN                                                   null

End of function check_link

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
277.89 ms | 1015 KiB | 16 Q