3v4l.org

run code in 300+ PHP versions simultaneously
<?php function stripNonValidCharaters ($message) { $message = mb_convert_encoding($message, 'UTF-16', 'UTF-8'); $count = 0; //mostly taken from https://dynmark.uservoice.com/knowledgebase/articles/83496-gsm-alphabet-character-set $search = [ '`', '‘', '’', //single quotes '“', '”', //double quotes '~', '¬', '|', //misc chr(0xc2a0) //nbsp character ]; $replace = [ "'", "'", "'", //single quotes '"', '"', //double quotes '-', '-', 'I', //misc " " //space ]; $message = str_replace($search, $replace, $message, $count); $message = trim($message); return ['message' => $message, 'replacements' => $count]; } $message = "We can’t wait to see you at our Open Day next week. We’ve sent you an email with all the info you need. If you’ve not received it please call 01252 892883"; var_dump(stripNonValidCharaters($message));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ufS7I
function name:  (null)
number of ops:  8
compiled vars:  !0 = $message
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   ASSIGN                                                   !0, 'We+can%E2%80%99t+wait+to+see+you+at+our+Open+Day+next+week.+We%E2%80%99ve+sent+you+an+email+with+all+the+info+you+need.+If+you%E2%80%99ve+not+received+it+please+call+01252+892883'
   32     1        INIT_FCALL                                               'var_dump'
          2        INIT_FCALL                                               'stripnonvalidcharaters'
          3        SEND_VAR                                                 !0
          4        DO_FCALL                                      0  $2      
          5        SEND_VAR                                                 $2
          6        DO_ICALL                                                 
          7      > RETURN                                                   1

Function stripnonvalidcharaters:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ufS7I
function name:  stripNonValidCharaters
number of ops:  34
compiled vars:  !0 = $message, !1 = $count, !2 = $search, !3 = $replace
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        INIT_FCALL                                               'mb_convert_encoding'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 'UTF-16'
          4        SEND_VAL                                                 'UTF-8'
          5        DO_ICALL                                         $4      
          6        ASSIGN                                                   !0, $4
    5     7        ASSIGN                                                   !1, 0
    9     8        INIT_ARRAY                                       ~7      '%60'
          9        ADD_ARRAY_ELEMENT                                ~7      '%E2%80%98'
         10        ADD_ARRAY_ELEMENT                                ~7      '%E2%80%99'
   10    11        ADD_ARRAY_ELEMENT                                ~7      '%E2%80%9C'
         12        ADD_ARRAY_ELEMENT                                ~7      '%E2%80%9D'
   11    13        ADD_ARRAY_ELEMENT                                ~7      '%7E'
         14        ADD_ARRAY_ELEMENT                                ~7      '%C2%AC'
         15        ADD_ARRAY_ELEMENT                                ~7      '%7C'
   12    16        ADD_ARRAY_ELEMENT                                ~7      '%A0'
    8    17        ASSIGN                                                   !2, ~7
   14    18        ASSIGN                                                   !3, <array>
   21    19        INIT_FCALL                                               'str_replace'
         20        SEND_VAR                                                 !2
         21        SEND_VAR                                                 !3
         22        SEND_VAR                                                 !0
         23        SEND_REF                                                 !1
         24        DO_ICALL                                         $10     
         25        ASSIGN                                                   !0, $10
   24    26        INIT_FCALL                                               'trim'
         27        SEND_VAR                                                 !0
         28        DO_ICALL                                         $12     
         29        ASSIGN                                                   !0, $12
   26    30        INIT_ARRAY                                       ~14     !0, 'message'
         31        ADD_ARRAY_ELEMENT                                ~14     !1, 'replacements'
         32      > RETURN                                                   ~14
   27    33*     > RETURN                                                   null

End of function stripnonvalidcharaters

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
156.3 ms | 1403 KiB | 22 Q