3v4l.org

run code in 300+ PHP versions simultaneously
<?php $str = '<p>\' ‘ ’ ‚ " “ ” „ &amp;amp; © ® ™ ° &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</p>'; echo clean($str); echo PHP_EOL.PHP_EOL; $htmlent = htmlentities($str, ENT_HTML5 | ENT_QUOTES, 'UTF-8'); echo $htmlent; echo PHP_EOL.PHP_EOL; echo htmlentity_decode($htmlent); function clean($str_clean, $strict_clean = true, $punct_clean = true) { $base_pool = array( '‘' => '&lsquo;', '’' => '&rsquo;', '‚' => '&sbquo;', '“' => '&ldquo;', '”' => '&rdquo;', '„' => '&bdquo;', '©' => '&copy;', '®' => '&reg;', '™' => '&trade;', '°' => '&deg;', '•' => '&bull;', '–' => '&ndash;', '—' => '&mdash;', '…' => '&#8230;', '¼' => '&#188;', '½' => '&#189;', '¾' => '&#190;', '‰' => '&#8240;', '±' => '&#177;', '†' => '&#8224;', '‡' => '&#8225;', '&amp;amp;' => '&amp;', '&nbsp;' => ' ' ); $strict_pool = array( '\'' => '&#39;', '"' => '&quot;', "\r" => ' ', "\n" => ' ', "\t" => ' ' ); // if strict param is true we will clean harder (default true) if ($strict_clean) { $base_pool = array_merge($strict_pool, $base_pool); } foreach ($base_pool as $key => $value) { $str_clean = str_replace($key, $value, $str_clean); // iterate through pool key => values and replace in $str_clean } // if punct param is true we will add spaces after punctuation (default true) if ($punct_clean) { $str_clean = preg_replace('/([!?,.])(\S)/', '$1 $2', $str_clean); // parse punctuation and add trail space } $str_clean = preg_replace("/\s+/", ' ', $str_clean); // filter multiple spaces into single return $str_clean; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Y0RMq
function name:  (null)
number of ops:  19
compiled vars:  !0 = $str, !1 = $htmlent
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%3Cp%3E%27+%E2%80%98+%E2%80%99+%E2%80%9A+%22+%E2%80%9C+%E2%80%9D+%E2%80%9E+%26amp%3Bamp%3B+%C2%A9+%C2%AE+%E2%84%A2+%C2%B0++%26nbsp%3B++%26nbsp%3B++++%26nbsp%3B++%26nbsp%3B++++++%26nbsp%3B+++%26nbsp%3B%3C%2Fp%3E'
    5     1        INIT_FCALL_BY_NAME                                       'clean'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0  $3      
          4        ECHO                                                     $3
    7     5        ECHO                                                     '%0A%0A'
    9     6        INIT_FCALL                                               'htmlentities'
          7        SEND_VAR                                                 !0
          8        SEND_VAL                                                 51
          9        SEND_VAL                                                 'UTF-8'
         10        DO_ICALL                                         $4      
         11        ASSIGN                                                   !1, $4
   11    12        ECHO                                                     !1
   13    13        ECHO                                                     '%0A%0A'
   15    14        INIT_FCALL_BY_NAME                                       'htmlentity_decode'
         15        SEND_VAR_EX                                              !1
         16        DO_FCALL                                      0  $6      
         17        ECHO                                                     $6
   69    18      > RETURN                                                   1

Function clean:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 11
Branch analysis from position: 6
2 jumps found. (Code = 77) Position 1 = 12, Position 2 = 21
Branch analysis from position: 12
2 jumps found. (Code = 78) Position 1 = 13, Position 2 = 21
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 29
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 29
Branch analysis from position: 21
Branch analysis from position: 11
filename:       /in/Y0RMq
function name:  clean
number of ops:  37
compiled vars:  !0 = $str_clean, !1 = $strict_clean, !2 = $punct_clean, !3 = $base_pool, !4 = $strict_pool, !5 = $value, !6 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <true>
          2        RECV_INIT                                        !2      <true>
   18     3        ASSIGN                                                   !3, <array>
   44     4        ASSIGN                                                   !4, <array>
   53     5      > JMPZ                                                     !1, ->11
   54     6    >   INIT_FCALL                                               'array_merge'
          7        SEND_VAR                                                 !4
          8        SEND_VAR                                                 !3
          9        DO_ICALL                                         $9      
         10        ASSIGN                                                   !3, $9
   57    11    > > FE_RESET_R                                       $11     !3, ->21
         12    > > FE_FETCH_R                                       ~12     $11, !5, ->21
         13    >   ASSIGN                                                   !6, ~12
   58    14        INIT_FCALL                                               'str_replace'
         15        SEND_VAR                                                 !6
         16        SEND_VAR                                                 !5
         17        SEND_VAR                                                 !0
         18        DO_ICALL                                         $14     
         19        ASSIGN                                                   !0, $14
   57    20      > JMP                                                      ->12
         21    >   FE_FREE                                                  $11
   62    22      > JMPZ                                                     !2, ->29
   63    23    >   INIT_FCALL                                               'preg_replace'
         24        SEND_VAL                                                 '%2F%28%5B%21%3F%2C.%5D%29%28%5CS%29%2F'
         25        SEND_VAL                                                 '%241+%242'
         26        SEND_VAR                                                 !0
         27        DO_ICALL                                         $16     
         28        ASSIGN                                                   !0, $16
   66    29    >   INIT_FCALL                                               'preg_replace'
         30        SEND_VAL                                                 '%2F%5Cs%2B%2F'
         31        SEND_VAL                                                 '+'
         32        SEND_VAR                                                 !0
         33        DO_ICALL                                         $18     
         34        ASSIGN                                                   !0, $18
   68    35      > RETURN                                                   !0
   69    36*     > RETURN                                                   null

End of function clean

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
169.13 ms | 945 KiB | 22 Q