3v4l.org

run code in 300+ 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 = 28
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aJ3HO
function name:  {closure}
number of ops:  34
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    >   INIT_FCALL                                               'sprintf'
          5        SEND_VAL                                                 '%3Ca+href%3D%22%25s%22%3E%25s%3C%2Fa%3E'
          6        FETCH_DIM_R                                      ~3      !0, 0
          7        SEND_VAL                                                 ~3
          8        FETCH_DIM_R                                      ~4      !0, 0
          9        SEND_VAL                                                 ~4
         10        DO_ICALL                                         $5      
         11      > RETURN                                                   $5
   15    12    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~6      !0, 2
         13        BOOL_NOT                                         ~7      ~6
         14      > JMPZ                                                     ~7, ->28
   16    15    >   INIT_FCALL                                               'sprintf'
         16        SEND_VAL                                                 '%3Ca+href%3D%22%25s%3D%25s%22%3E%25s%3C%2Fa%3E'
         17        FETCH_CONSTANT                                   ~8      'PINGTAGS'
         18        FETCH_DIM_R                                      ~9      !0, 0
         19        FETCH_DIM_R                                      ~10     ~9, 0
         20        FETCH_DIM_R                                      ~11     ~8, ~10
         21        SEND_VAL                                                 ~11
         22        FETCH_DIM_R                                      ~12     !0, 1
         23        SEND_VAL                                                 ~12
         24        FETCH_DIM_R                                      ~13     !0, 0
         25        SEND_VAL                                                 ~13
         26        DO_ICALL                                         $14     
         27      > RETURN                                                   $14
   18    28    >   ROPE_INIT                                     3  ~17     '%3Cspan+class%3D%22emoji%22%3E%26%23x'
         29        FETCH_DIM_R                                      ~15     !0, 2
         30        ROPE_ADD                                      1  ~17     ~17, ~15
         31        ROPE_END                                      2  ~16     ~17, '%3B%3C%2Fspan%3E'
         32      > RETURN                                                   ~16
   19    33*     > RETURN                                                   null

End of Dynamic Function 0

End of function convert_text

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
144.14 ms | 1011 KiB | 17 Q