3v4l.org

run code in 300+ PHP versions simultaneously
<?php error_reporting(-1); mb_internal_encoding('utf-8'); $text = "ну что. не смотрел еще black mesa.я собирался скачать ,но все как-то некогда было."; // Для тестов // $text = 'roses are red,and violets are blue.whatever you do i'll keep it for you.'; // $text = 'привет.есть 2 функции,preg_split и explode ,не понимаю,в чем между ними разница.'; /* Делает первую букву в строке заглавной */ function makeFirstLetterUppercase($text) { $sentences = preg_split("/(?<=[!\?\.])/u", $text, -1, PREG_SPLIT_NO_EMPTY); $countSentences = count($sentences); for ($i = 0; $i < $countSentences; $i++){ $sentences[1] = trim($sentences[1]); $sentences[$i] = mb_ucfirst($sentences[$i]); } $text=implode($sentences); return($text); } function mb_ucfirst($str, $encoding = NULL) { if($encoding === NULL) { $encoding = mb_internal_encoding(); } return mb_substr(mb_strtoupper($str, $encoding), 0, 1, $encoding) . mb_substr($str, 1, mb_strlen($str)-1, $encoding); } /* исправляет текст */ function fixText($text) { $patterns=array(); $patterns[1]='/(\\s+)?,(\\s+)?/u'; $patterns[2]='/[.]/u'; $replacements=array(); $replacements[1]=", "; $replacements[2]=". "; $text=preg_replace($patterns,$replacements,$text); return($text); } function ucfirst_utf8($str) { return mb_substr(mb_strtoupper($str, 'utf-8'), 0, 1, 'utf-8') . mb_substr($str, 1, mb_strlen($str)-1, 'utf-8'); } $text = makeFirstLetterUppercase($text); //$result = fixText($text); echo "{$text}\n";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JJOFn
function name:  (null)
number of ops:  15
compiled vars:  !0 = $text
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                               'error_reporting'
          1        SEND_VAL                                                 -1
          2        DO_ICALL                                                 
    4     3        INIT_FCALL                                               'mb_internal_encoding'
          4        SEND_VAL                                                 'utf-8'
          5        DO_ICALL                                                 
    6     6        ASSIGN                                                   !0, '%D0%BD%D1%83+%D1%87%D1%82%D0%BE.++++++%D0%BD%D0%B5+%D1%81%D0%BC%D0%BE%D1%82%D1%80%D0%B5%D0%BB+%D0%B5%D1%89%D0%B5+black+mesa.%D1%8F+%D1%81%D0%BE%D0%B1%D0%B8%D1%80%D0%B0%D0%BB%D1%81%D1%8F+%D1%81%D0%BA%D0%B0%D1%87%D0%B0%D1%82%D1%8C++%2C%D0%BD%D0%BE+%D0%B2%D1%81%D0%B5+%D0%BA%D0%B0%D0%BA-%D1%82%D0%BE+%D0%BD%D0%B5%D0%BA%D0%BE%D0%B3%D0%B4%D0%B0+%D0%B1%D1%8B%D0%BB%D0%BE.'
   58     7        INIT_FCALL                                               'makefirstletteruppercase'
          8        SEND_VAR                                                 !0
          9        DO_FCALL                                      0  $4      
         10        ASSIGN                                                   !0, $4
   60    11        NOP                                                      
         12        FAST_CONCAT                                      ~6      !0, '%0A'
         13        ECHO                                                     ~6
         14      > RETURN                                                   1

Function makefirstletteruppercase:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
2 jumps found. (Code = 44) Position 1 = 28, Position 2 = 12
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
2 jumps found. (Code = 44) Position 1 = 28, Position 2 = 12
Branch analysis from position: 28
Branch analysis from position: 12
filename:       /in/JJOFn
function name:  makeFirstLetterUppercase
number of ops:  34
compiled vars:  !0 = $text, !1 = $sentences, !2 = $countSentences, !3 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
   13     1        INIT_FCALL                                               'preg_split'
          2        SEND_VAL                                                 '%2F%28%3F%3C%3D%5B%21%5C%3F%5C.%5D%29%2Fu'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 -1
          5        SEND_VAL                                                 1
          6        DO_ICALL                                         $4      
          7        ASSIGN                                                   !1, $4
   14     8        COUNT                                            ~6      !1
          9        ASSIGN                                                   !2, ~6
   15    10        ASSIGN                                                   !3, 0
         11      > JMP                                                      ->26
   16    12    >   INIT_FCALL                                               'trim'
         13        FETCH_DIM_R                                      ~10     !1, 1
         14        SEND_VAL                                                 ~10
         15        DO_ICALL                                         $11     
         16        ASSIGN_DIM                                               !1, 1
         17        OP_DATA                                                  $11
   17    18        INIT_FCALL_BY_NAME                                       'mb_ucfirst'
         19        CHECK_FUNC_ARG                                           
         20        FETCH_DIM_FUNC_ARG                               $13     !1, !3
         21        SEND_FUNC_ARG                                            $13
         22        DO_FCALL                                      0  $14     
         23        ASSIGN_DIM                                               !1, !3
         24        OP_DATA                                                  $14
   15    25        PRE_INC                                                  !3
         26    >   IS_SMALLER                                               !3, !2
         27      > JMPNZ                                                    ~16, ->12
   19    28    >   INIT_FCALL                                               'implode'
         29        SEND_VAR                                                 !1
         30        DO_ICALL                                         $17     
         31        ASSIGN                                                   !0, $17
   20    32      > RETURN                                                   !0
   21    33*     > RETURN                                                   null

End of function makefirstletteruppercase

Function mb_ucfirst:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 7
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
filename:       /in/JJOFn
function name:  mb_ucfirst
number of ops:  30
compiled vars:  !0 = $str, !1 = $encoding
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      null
   25     2        TYPE_CHECK                                    2          !1
          3      > JMPZ                                                     ~2, ->7
   27     4    >   INIT_FCALL                                               'mb_internal_encoding'
          5        DO_ICALL                                         $3      
          6        ASSIGN                                                   !1, $3
   30     7    >   INIT_FCALL                                               'mb_substr'
          8        INIT_FCALL                                               'mb_strtoupper'
          9        SEND_VAR                                                 !0
         10        SEND_VAR                                                 !1
         11        DO_ICALL                                         $5      
         12        SEND_VAR                                                 $5
         13        SEND_VAL                                                 0
         14        SEND_VAL                                                 1
         15        SEND_VAR                                                 !1
         16        DO_ICALL                                         $6      
         17        INIT_FCALL                                               'mb_substr'
         18        SEND_VAR                                                 !0
         19        SEND_VAL                                                 1
         20        INIT_FCALL                                               'mb_strlen'
         21        SEND_VAR                                                 !0
         22        DO_ICALL                                         $7      
         23        SUB                                              ~8      $7, 1
         24        SEND_VAL                                                 ~8
         25        SEND_VAR                                                 !1
         26        DO_ICALL                                         $9      
         27        CONCAT                                           ~10     $6, $9
         28      > RETURN                                                   ~10
   31    29*     > RETURN                                                   null

End of function mb_ucfirst

Function fixtext:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JJOFn
function name:  fixText
number of ops:  19
compiled vars:  !0 = $text, !1 = $patterns, !2 = $replacements
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     0  E >   RECV                                             !0      
   39     1        ASSIGN                                                   !1, <array>
   40     2        ASSIGN_DIM                                               !1, 1
          3        OP_DATA                                                  '%2F%28%5Cs%2B%29%3F%2C%28%5Cs%2B%29%3F%2Fu'
   41     4        ASSIGN_DIM                                               !1, 2
          5        OP_DATA                                                  '%2F%5B.%5D%2Fu'
   44     6        ASSIGN                                                   !2, <array>
   45     7        ASSIGN_DIM                                               !2, 1
          8        OP_DATA                                                  '%2C+'
   46     9        ASSIGN_DIM                                               !2, 2
         10        OP_DATA                                                  '.+'
   48    11        INIT_FCALL                                               'preg_replace'
         12        SEND_VAR                                                 !1
         13        SEND_VAR                                                 !2
         14        SEND_VAR                                                 !0
         15        DO_ICALL                                         $9      
         16        ASSIGN                                                   !0, $9
   49    17      > RETURN                                                   !0
   51    18*     > RETURN                                                   null

End of function fixtext

Function ucfirst_utf8:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JJOFn
function name:  ucfirst_utf8
number of ops:  24
compiled vars:  !0 = $str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   53     0  E >   RECV                                             !0      
   55     1        INIT_FCALL                                               'mb_substr'
          2        INIT_FCALL                                               'mb_strtoupper'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 'utf-8'
          5        DO_ICALL                                         $1      
          6        SEND_VAR                                                 $1
          7        SEND_VAL                                                 0
          8        SEND_VAL                                                 1
          9        SEND_VAL                                                 'utf-8'
         10        DO_ICALL                                         $2      
         11        INIT_FCALL                                               'mb_substr'
         12        SEND_VAR                                                 !0
         13        SEND_VAL                                                 1
         14        INIT_FCALL                                               'mb_strlen'
         15        SEND_VAR                                                 !0
         16        DO_ICALL                                         $3      
         17        SUB                                              ~4      $3, 1
         18        SEND_VAL                                                 ~4
         19        SEND_VAL                                                 'utf-8'
         20        DO_ICALL                                         $5      
         21        CONCAT                                           ~6      $2, $5
         22      > RETURN                                                   ~6
   56    23*     > RETURN                                                   null

End of function ucfirst_utf8

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
182.38 ms | 1411 KiB | 32 Q