3v4l.org

run code in 300+ PHP versions simultaneously
<?php function sanitize_sentence($string) { $pats = array( '/([.!?]\s{2}),/', # Abc. ,Def '/\.+(,)/', # ......, '/(!|\?)\1+/', # abc!!!!!!!!, abc????????? '/\s+(,)/', # abc , def '/([a-zA-Z])\1\1/'); # greeeeeeen $fixed = preg_replace($pats,'$1',$string); $fixed = preg_replace('/,(?!\s)/',', ',$fixed); $fixed = preg_replace( '/([!?,.])(\S)/', '$1 $2', $fixed); $fixed = preg_replace( '/[^a-zA-Z0-9!?.]+$/', '.', $fixed); return $fixed; } echo sanitize_sentence('hello!!!!!!there should be a space after the exclamation mark.right. yes.right,');
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/rdcFh
function name:  (null)
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   INIT_FCALL                                               'sanitize_sentence'
          1        SEND_VAL                                                 'hello%21%21%21%21%21%21there+should+be+a+space+after+the+exclamation+mark.right.+yes.right%2C'
          2        DO_FCALL                                      0  $0      
          3        ECHO                                                     $0
          4      > RETURN                                                   1

Function sanitize_sentence:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/rdcFh
function name:  sanitize_sentence
number of ops:  28
compiled vars:  !0 = $string, !1 = $pats, !2 = $fixed
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
    3     1        ASSIGN                                                   !1, <array>
    9     2        INIT_FCALL                                               'preg_replace'
          3        SEND_VAR                                                 !1
          4        SEND_VAL                                                 '%241'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $4      
          7        ASSIGN                                                   !2, $4
   10     8        INIT_FCALL                                               'preg_replace'
          9        SEND_VAL                                                 '%2F%2C%28%3F%21%5Cs%29%2F'
         10        SEND_VAL                                                 '%2C+'
         11        SEND_VAR                                                 !2
         12        DO_ICALL                                         $6      
         13        ASSIGN                                                   !2, $6
   11    14        INIT_FCALL                                               'preg_replace'
         15        SEND_VAL                                                 '%2F%28%5B%21%3F%2C.%5D%29%28%5CS%29%2F'
         16        SEND_VAL                                                 '%241+%242'
         17        SEND_VAR                                                 !2
         18        DO_ICALL                                         $8      
         19        ASSIGN                                                   !2, $8
   12    20        INIT_FCALL                                               'preg_replace'
         21        SEND_VAL                                                 '%2F%5B%5Ea-zA-Z0-9%21%3F.%5D%2B%24%2F'
         22        SEND_VAL                                                 '.'
         23        SEND_VAR                                                 !2
         24        DO_ICALL                                         $10     
         25        ASSIGN                                                   !2, $10
   13    26      > RETURN                                                   !2
   14    27*     > RETURN                                                   null

End of function sanitize_sentence

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
170.33 ms | 1390 KiB | 16 Q