3v4l.org

run code in 300+ PHP versions simultaneously
<?php function convertHashtags($str) { $regex = '/@([a-zA-Z0-9]+[\sa-zA-Z0-9]*)/'; if(preg_match($regex,$str,$matches) === 1){ list($username,$name) = [$str , strtolower(str_replace(' ','',$matches[1]))]; return "<a href='profile?id=$name'>$username</a>"; } throw new Exception('Unable to find username in the given string'); } $string = 'I am @Marie Lee, nice to meet you!'; $string = convertHashtags($string); echo $string;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/dCQ4S
function name:  (null)
number of ops:  7
compiled vars:  !0 = $string
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   ASSIGN                                                   !0, 'I+am+%40Marie+Lee%2C+nice+to+meet+you%21'
   12     1        INIT_FCALL                                               'converthashtags'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0  $2      
          4        ASSIGN                                                   !0, $2
   13     5        ECHO                                                     !0
   14     6      > RETURN                                                   1

Function converthashtags:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 31
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 31
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/dCQ4S
function name:  convertHashtags
number of ops:  36
compiled vars:  !0 = $str, !1 = $regex, !2 = $matches, !3 = $username, !4 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
    3     1        ASSIGN                                                   !1, '%2F%40%28%5Ba-zA-Z0-9%5D%2B%5B%5Csa-zA-Z0-9%5D%2A%29%2F'
    4     2        INIT_FCALL                                               'preg_match'
          3        SEND_VAR                                                 !1
          4        SEND_VAR                                                 !0
          5        SEND_REF                                                 !2
          6        DO_ICALL                                         $6      
          7        IS_IDENTICAL                                             $6, 1
          8      > JMPZ                                                     ~7, ->31
    5     9    >   INIT_ARRAY                                       ~8      !0
         10        INIT_FCALL                                               'strtolower'
         11        INIT_FCALL                                               'str_replace'
         12        SEND_VAL                                                 '+'
         13        SEND_VAL                                                 ''
         14        FETCH_DIM_R                                      ~9      !2, 1
         15        SEND_VAL                                                 ~9
         16        DO_ICALL                                         $10     
         17        SEND_VAR                                                 $10
         18        DO_ICALL                                         $11     
         19        ADD_ARRAY_ELEMENT                                ~8      $11
         20        FETCH_LIST_R                                     $12     ~8, 0
         21        ASSIGN                                                   !3, $12
         22        FETCH_LIST_R                                     $14     ~8, 1
         23        ASSIGN                                                   !4, $14
         24        FREE                                                     ~8
    6    25        ROPE_INIT                                     5  ~17     '%3Ca+href%3D%27profile%3Fid%3D'
         26        ROPE_ADD                                      1  ~17     ~17, !4
         27        ROPE_ADD                                      2  ~17     ~17, '%27%3E'
         28        ROPE_ADD                                      3  ~17     ~17, !3
         29        ROPE_END                                      4  ~16     ~17, '%3C%2Fa%3E'
         30      > RETURN                                                   ~16
    8    31    >   NEW                                              $20     'Exception'
         32        SEND_VAL_EX                                              'Unable+to+find+username+in+the+given+string'
         33        DO_FCALL                                      0          
         34      > THROW                                         0          $20
    9    35*     > RETURN                                                   null

End of function converthashtags

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
141 ms | 1007 KiB | 17 Q