3v4l.org

run code in 500+ PHP versions simultaneously
<?php define('PINGTAGS', [ '#' => 'hashtag.php?hashtag', '@' => 'user.php?user' ]); function convert_text($str) { return preg_replace_callback( "~(?i)\bhttps?[-\w.\~:/?#[\]@!$&'()*+,;=]+|[@#](\w+)|U\+([A-F\d]{5})~", function($m) { // var_export($m); // see for yourself if (!isset($m[1])) { return sprintf('<a href="%s">%s</a>', $m[0], $m[0]); } if (!isset($m[2])) { return sprintf('<a href="%s=%s">%s</a>', PINGTAGS[$m[0][0]], $m[1], $m[0]); } return "<span class=\"emoji\">&#x{$m[2]};</span>"; }, $str); } echo convert_text( <<<STRING This is a @ping and a #hash. This is a www.example.com, this is http://example.com?asdf=1234#anchor https://www.example.net/a/b/c/?g=5&awesome=foobar# U+23232 http://www5.example.com https://sub.sub.www.example.org/ @pong@pug#tagged http://example.com/@dave more http://example.com/more_(than)_one_(parens) andU+98765more http://example.com/blah_(wikipedia)#cite-1 and more http://example.com/blah_(wikipedia)_blah#cite-1 and more http://example.com/(something)?after=parens STRING );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aJ3HO
function name:  (null)
number of ops:  9
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    2     0  E >   INIT_FCALL                                                   'define'
          1        SEND_VAL                                                     'PINGTAGS'
    3     2        SEND_VAL                                                     <array>
    2     3        DO_ICALL                                                     
   24     4        INIT_FCALL                                                   'convert_text'
   26     5        SEND_VAL                                                     'This+is+a+%40ping+and+a+%23hash.%0AThis+is+a+www.example.com%2C+this+is+http%3A%2F%2Fexample.com%3Fasdf%3D1234%23anchor%0Ahttps%3A%2F%2Fwww.example.net%2Fa%2Fb%2Fc%2F%3Fg%3D5%26awesome%3Dfoobar%23+U%2B23232+http%3A%2F%2Fwww5.example.com%0Ahttps%3A%2F%2Fsub.sub.www.example.org%2F+%40pong%40pug%23tagged%0Ahttp%3A%2F%2Fexample.com%2F%40dave%0Amore+http%3A%2F%2Fexample.com%2Fmore_%28than%29_one_%28parens%29%0AandU%2B98765more+http%3A%2F%2Fexample.com%2Fblah_%28wikipedia%29%23cite-1%0Aand+more+http%3A%2F%2Fexample.com%2Fblah_%28wikipedia%29_blah%23cite-1%0Aand+more+http%3A%2F%2Fexample.com%2F%28something%29%3Fafter%3Dparens'
   24     6        DO_FCALL                                          0  $1      
   26     7        ECHO                                                         $1
   36     8      > RETURN                                                       1

Function convert_text:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aJ3HO
function name:  convert_text
number of ops:  9
compiled vars:  !0 = $str
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    7     0  E >   RECV                                                 !0      
    8     1        INIT_FCALL                                                   'preg_replace_callback'
    9     2        SEND_VAL                                                     '%7E%28%3Fi%29%5Cbhttps%3F%5B-%5Cw.%5C%7E%3A%2F%3F%23%5B%5C%5D%40%21%24%26%27%28%29%2A%2B%2C%3B%3D%5D%2B%7C%5B%40%23%5D%28%5Cw%2B%29%7CU%5C%2B%28%5BA-F%5Cd%5D%7B5%7D%29%7E'
   10     3        DECLARE_LAMBDA_FUNCTION                              ~1      [0]
   19     4        SEND_VAL                                                     ~1
   20     5        SEND_VAR                                                     !0
    8     6        DO_ICALL                                             $2      
   20     7      > RETURN                                                       $2
   21     8*     > RETURN                                                       null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 12
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 29
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aJ3HO
function name:  {closure:convert_text():10}
number of ops:  35
compiled vars:  !0 = $m
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   10     0  E >   RECV                                                 !0      
   12     1        ISSET_ISEMPTY_DIM_OBJ                             0  ~1      !0, 1
          2        BOOL_NOT                                             ~2      ~1
          3      > JMPZ                                                         ~2, ->12
   13     4    >   FETCH_DIM_R                                          ~3      !0, 0
          5        FETCH_DIM_R                                          ~4      !0, 0
          6        ROPE_INIT                                         5  ~6      '%3Ca+href%3D%22'
          7        ROPE_ADD                                          1  ~6      ~6, ~3
          8        ROPE_ADD                                          2  ~6      ~6, '%22%3E'
          9        ROPE_ADD                                          3  ~6      ~6, ~4
         10        ROPE_END                                          4  ~5      ~6, '%3C%2Fa%3E'
         11      > RETURN                                                       ~5
   15    12    >   ISSET_ISEMPTY_DIM_OBJ                             0  ~9      !0, 2
         13        BOOL_NOT                                             ~10     ~9
         14      > JMPZ                                                         ~10, ->29
   16    15    >   FETCH_CONSTANT                                       ~11     'PINGTAGS'
         16        FETCH_DIM_R                                          ~12     !0, 0
         17        FETCH_DIM_R                                          ~13     ~12, 0
         18        FETCH_DIM_R                                          ~14     ~11, ~13
         19        FETCH_DIM_R                                          ~15     !0, 1
         20        FETCH_DIM_R                                          ~16     !0, 0
         21        ROPE_INIT                                         7  ~18     '%3Ca+href%3D%22'
         22        ROPE_ADD                                          1  ~18     ~18, ~14
         23        ROPE_ADD                                          2  ~18     ~18, '%3D'
         24        ROPE_ADD                                          3  ~18     ~18, ~15
         25        ROPE_ADD                                          4  ~18     ~18, '%22%3E'
         26        ROPE_ADD                                          5  ~18     ~18, ~16
         27        ROPE_END                                          6  ~17     ~18, '%3C%2Fa%3E'
         28      > RETURN                                                       ~17
   18    29    >   ROPE_INIT                                         3  ~24     '%3Cspan+class%3D%22emoji%22%3E%26%23x'
         30        FETCH_DIM_R                                          ~22     !0, 2
         31        ROPE_ADD                                          1  ~24     ~24, ~22
         32        ROPE_END                                          2  ~23     ~24, '%3B%3C%2Fspan%3E'
         33      > RETURN                                                       ~23
   19    34*     > RETURN                                                       null

End of Dynamic Function 0

End of function convert_text

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
161.28 ms | 2394 KiB | 16 Q