3v4l.org

run code in 500+ 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/qiIq2
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%3F%3F%3F%3F%3F%3F%3Fyes.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/qiIq2
function name:  sanitize_sentence
number of ops:  16
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        FRAMELESS_ICALL_3                preg_replace        ~4      !1, '%241'
          3        OP_DATA                                                      !0
          4        ASSIGN                                                       !2, ~4
   10     5        FRAMELESS_ICALL_3                preg_replace        ~6      '%2F%2C%28%3F%21%5Cs%29%2F', '%2C+'
          6        OP_DATA                                                      !2
          7        ASSIGN                                                       !2, ~6
   11     8        FRAMELESS_ICALL_3                preg_replace        ~8      '%2F%28%5B%21%3F%2C.%5D%29%28%5CS%29%2F', '%241+%242'
          9        OP_DATA                                                      !2
         10        ASSIGN                                                       !2, ~8
   12    11        FRAMELESS_ICALL_3                preg_replace        ~10     '%2F%28%5B%5Ea-zA-Z0-9%21%3F.%5D%2B%29%24%2F', '.'
         12        OP_DATA                                                      !2
         13        ASSIGN                                                       !2, ~10
   13    14      > RETURN                                                       !2
   14    15*     > RETURN                                                       null

End of function sanitize_sentence

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
221.03 ms | 3325 KiB | 16 Q