3v4l.org

run code in 300+ PHP versions simultaneously
<?php function tagify($str, $baseUrl = '/board/') { $baseUrl = rtrim($baseUrl, '/'); return preg_replace('/ (?!<a[^<>]*>[^\#]*) # Dont match if there is an opening <a> tag and any chars after it. \#([-_\w]+\b) # Match the hashtag. (?![^<]*<\/a>) # Ignore any anding <\/a> tag including any chars before it not in hashtag. /ix', '<a href="'.$baseUrl.'/$1">#$1</a>', $str); } $str = <<<STR This is <a href="http://foo.com">This is #foo</a>. Simple #html-stuff text <a href="http://foobar.com#baz">#simple</a> <span class="simple">simple #simple text text</span> STR; echo tagify($str);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/unX8g
function name:  (null)
number of ops:  6
compiled vars:  !0 = $str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   ASSIGN                                                   !0, 'This+is+%3Ca+href%3D%22http%3A%2F%2Ffoo.com%22%3EThis+is+%23foo%3C%2Fa%3E.%0ASimple+%23html-stuff+text+%3Ca+href%3D%22http%3A%2F%2Ffoobar.com%23baz%22%3E%23simple%3C%2Fa%3E%0A%3Cspan+class%3D%22simple%22%3Esimple+%23simple+text+text%3C%2Fspan%3E%0A'
   20     1        INIT_FCALL                                               'tagify'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0  $2      
          4        ECHO                                                     $2
          5      > RETURN                                                   1

Function tagify:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/unX8g
function name:  tagify
number of ops:  16
compiled vars:  !0 = $str, !1 = $baseUrl
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      '%2Fboard%2F'
    5     2        INIT_FCALL                                               'rtrim'
          3        SEND_VAR                                                 !1
          4        SEND_VAL                                                 '%2F'
          5        DO_ICALL                                         $2      
          6        ASSIGN                                                   !1, $2
    6     7        INIT_FCALL                                               'preg_replace'
          8        SEND_VAL                                                 '%2F%0A%09++++%28%3F%21%3Ca%5B%5E%3C%3E%5D%2A%3E%5B%5E%5C%23%5D%2A%29+%23+Dont+match+if+there+is+an+opening+%3Ca%3E+tag+and+any+chars+after+it.%0A%09++++%5C%23%28%5B-_%5Cw%5D%2B%5Cb%29+++++++%23+Match+the+hashtag.%0A%09++++%28%3F%21%5B%5E%3C%5D%2A%3C%5C%2Fa%3E%29+++++%23+Ignore+any+anding+%3C%5C%2Fa%3E+tag+including+any+chars+before+it+not+in+hashtag.%0A%09%2Fix'
   10     9        CONCAT                                           ~4      '%3Ca+href%3D%22', !1
         10        CONCAT                                           ~5      ~4, '%2F%241%22%3E%23%241%3C%2Fa%3E'
         11        SEND_VAL                                                 ~5
         12        SEND_VAR                                                 !0
         13        DO_ICALL                                         $6      
         14      > RETURN                                                   $6
   11    15*     > RETURN                                                   null

End of function tagify

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.38 ms | 1399 KiB | 18 Q