3v4l.org

run code in 500+ 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 = 25
Branch analysis from position: 15
2 jumps found. (Code = 78) Position 1 = 16, Position 2 = 25
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
filename:       /in/85lsl
function name:  preventXssAndParseAnchors
number of ops:  30
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, ->25
         15    > > FE_FETCH_R                                                   $9, !3, ->25
   17    16    >   ROPE_INIT                                         5  ~11     '%3Ca+href%3D%27'
         17        ROPE_ADD                                          1  ~11     ~11, !3
         18        ROPE_ADD                                          2  ~11     ~11, '%27%3E'
         19        ROPE_ADD                                          3  ~11     ~11, !3
         20        ROPE_END                                          4  ~10     ~11, '%3C%2Fa%3E'
         21        FRAMELESS_ICALL_3                str_replace         ~14     !3, ~10
         22        OP_DATA                                                      !0
         23        ASSIGN                                                       !0, ~14
   16    24      > JMP                                                          ->15
         25    >   FE_FREE                                                      $9
   20    26        VERIFY_RETURN_TYPE                                           !0
         27      > RETURN                                                       !0
   21    28*       VERIFY_RETURN_TYPE                                           
         29*     > RETURN                                                       null

End of function preventxssandparseanchors

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
182.23 ms | 1951 KiB | 16 Q