3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * @param string $str the string to encode and parse for URLs */ function preventXssAndParseAnchors(string $str): string { $url_regex = "/\b((https?:\/\/?|www\.)[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|\/)))/"; // Encoding HTML special characters To prevent XSS // Before parsing the URLs to Anchors $str = htmlspecialchars($str, ENT_QUOTES, 'UTF-8'); preg_match_all($url_regex, $str, $urls); foreach ($urls[0] as $url) { $str = str_replace($url, "<a href='$url'>$url</a>", $str); } return $str; } $str = " apply here https://ph.dbsd.com/job/dfvdfg/5444 <script> console.log('this is a hacking attempt hacking'); </script> and www.google.com also http://somesite.net "; echo preventXssAndParseAnchors($str);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/85lsl
function name:  (null)
number of ops:  6
compiled vars:  !0 = $str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   ASSIGN                                                   !0, '%0Aapply+here+https%3A%2F%2Fph.dbsd.com%2Fjob%2Fdfvdfg%2F5444%0A%0A%3Cscript%3E+console.log%28%27this+is+a+hacking+attempt+hacking%27%29%3B+%3C%2Fscript%3E%0A%0Aand+www.google.com%0A%0Aalso+http%3A%2F%2Fsomesite.net%0A'
   33     1        INIT_FCALL                                               'preventxssandparseanchors'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0  $2      
          4        ECHO                                                     $2
          5      > RETURN                                                   1

Function preventxssandparseanchors:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 15, Position 2 = 28
Branch analysis from position: 15
2 jumps found. (Code = 78) Position 1 = 16, Position 2 = 28
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 28
filename:       /in/85lsl
function name:  preventXssAndParseAnchors
number of ops:  33
compiled vars:  !0 = $str, !1 = $url_regex, !2 = $urls, !3 = $url
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
    8     1        ASSIGN                                                   !1, '%2F%5Cb%28%28https%3F%3A%5C%2F%5C%2F%3F%7Cwww%5C.%29%5B%5E%5Cs%28%29%3C%3E%5D%2B%28%3F%3A%5C%28%5B%5Cw%5Cd%5D%2B%5C%29%7C%28%5B%5E%5B%3Apunct%3A%5D%5Cs%5D%7C%5C%2F%29%29%29%2F'
   12     2        INIT_FCALL                                               'htmlspecialchars'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 3
          5        SEND_VAL                                                 'UTF-8'
          6        DO_ICALL                                         $5      
          7        ASSIGN                                                   !0, $5
   14     8        INIT_FCALL                                               'preg_match_all'
          9        SEND_VAR                                                 !1
         10        SEND_VAR                                                 !0
         11        SEND_REF                                                 !2
         12        DO_ICALL                                                 
   16    13        FETCH_DIM_R                                      ~8      !2, 0
         14      > FE_RESET_R                                       $9      ~8, ->28
         15    > > FE_FETCH_R                                               $9, !3, ->28
   17    16    >   INIT_FCALL                                               'str_replace'
         17        SEND_VAR                                                 !3
         18        ROPE_INIT                                     5  ~11     '%3Ca+href%3D%27'
         19        ROPE_ADD                                      1  ~11     ~11, !3
         20        ROPE_ADD                                      2  ~11     ~11, '%27%3E'
         21        ROPE_ADD                                      3  ~11     ~11, !3
         22        ROPE_END                                      4  ~10     ~11, '%3C%2Fa%3E'
         23        SEND_VAL                                                 ~10
         24        SEND_VAR                                                 !0
         25        DO_ICALL                                         $14     
         26        ASSIGN                                                   !0, $14
   16    27      > JMP                                                      ->15
         28    >   FE_FREE                                                  $9
   20    29        VERIFY_RETURN_TYPE                                       !0
         30      > RETURN                                                   !0
   21    31*       VERIFY_RETURN_TYPE                                       
         32*     > RETURN                                                   null

End of function preventxssandparseanchors

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.09 ms | 1020 KiB | 17 Q