3v4l.org

run code in 300+ PHP versions simultaneously
<?php function tagify($str, $baseUrl = '/board/') { $regExp = '/ (?!<a[^<>]*>[^\#]*) # Dont match if there is an opening link tag and any chars after it. \#([-_\w]+\b) # Match the hashtag. (?![^<]*<\/a>) # Ignore any closing link tag including any chars before it not in hashtag. /ix'; return preg_replace($regExp, '<a href="'.rtrim($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/8lvHn
function name:  (null)
number of ops:  6
compiled vars:  !0 = $str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     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'
   21     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/8lvHn
function name:  tagify
number of ops:  16
compiled vars:  !0 = $str, !1 = $baseUrl, !2 = $regExp
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      '%2Fboard%2F'
    5     2        ASSIGN                                                   !2, '%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+link+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+closing+link+tag+including+any+chars+before+it+not+in+hashtag.%0A%09%2Fix'
   11     3        INIT_FCALL                                               'preg_replace'
          4        SEND_VAR                                                 !2
          5        INIT_FCALL                                               'rtrim'
          6        SEND_VAR                                                 !1
          7        SEND_VAL                                                 '%2F'
          8        DO_ICALL                                         $4      
          9        CONCAT                                           ~5      '%3Ca+href%3D%22', $4
         10        CONCAT                                           ~6      ~5, '%2F%241%22%3E%23%241%3C%2Fa%3E'
         11        SEND_VAL                                                 ~6
         12        SEND_VAR                                                 !0
         13        DO_ICALL                                         $7      
         14      > RETURN                                                   $7
   12    15*     > RETURN                                                   null

End of function tagify

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
159.91 ms | 1399 KiB | 18 Q