3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types=1); mb_internal_encoding('utf-8'); error_reporting(E_ALL); $text1 = "ну что. не смотрел еще black mesa?я собирался скачать ,но все как-то некогда было!"; $text2 = " roses are red,and violets are blue.whatever you do I'll keep it for you."; $text3 = "привет.есть 2 функции,preg_split и explode ,не понимаю,в чем между ними разница."; $text4 = "много их в Петербурге,молоденьких дур,сегодня в атласе да бархате,а завтра , поглядишь , метут улицу вместе с голью кабацкою...в самом деле ,что было бы с нами ,если бы вместо общеудобного правила:чин чина почитай , ввелось в употребление другое,например:ум ума почитай?какие возникли бы споры!"; function makeFirstCharInSentenceUpperCase(string $sentence): string { $firstChar = mb_substr($sentence, 0, 1); $remainingSentence = mb_substr($sentence, 1); $upperFirstChar = mb_strtoupper($firstChar); return $upperFirstChar . $remainingSentence; } /** * @param string $sentence * * @return string * @throws RuntimeException */ function rearrangeSpacesInSentence(string $sentence): string { $rearrangedSentence = preg_replace( ['/\s\s+/', '/\s([.,:;!?])/', '/([.,:;!?])(\w)/u'], [' ', '$1', '$1 $2'], $sentence ); if (null === $rearrangedSentence) { throw new RuntimeException(preg_last_error_msg()); } return $rearrangedSentence; } /** * @param string $text * @param array<callable(string):string> $rules * * @return string * @throws RuntimeException */ function fixSentencesInTextByRules(string $text, array $rules): string { $sentences = preg_split('/(?<=[.!?])(?=[\w\s])/u', $text, -1, PREG_SPLIT_NO_EMPTY); foreach ($rules as $rule) { $sentences = array_map($rule, $sentences); } return implode(' ', $sentences); } $texts = [$text1, $text2, $text3, $text4]; $sentenceRules = [ trim(...), makeFirstCharInSentenceUpperCase(...), rearrangeSpacesInSentence(...), ]; foreach ($texts as $text) { echo fixSentencesInTextByRules($text, $sentenceRules), "\n"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 26, Position 2 = 34
Branch analysis from position: 26
2 jumps found. (Code = 78) Position 1 = 27, Position 2 = 34
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 34
filename:       /in/hkjXO
function name:  (null)
number of ops:  36
compiled vars:  !0 = $text1, !1 = $text2, !2 = $text3, !3 = $text4, !4 = $texts, !5 = $sentenceRules, !6 = $text
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                               'mb_internal_encoding'
          1        SEND_VAL                                                 'utf-8'
          2        DO_ICALL                                                 
    4     3        INIT_FCALL                                               'error_reporting'
          4        SEND_VAL                                                 32767
          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%3F%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%21'
    7     7        ASSIGN                                                   !1, '+roses+are++red%2Cand+violets++are+blue.whatever+you+do+++I%27ll+keep+it+for+you.'
    8     8        ASSIGN                                                   !2, '%D0%BF%D1%80%D0%B8%D0%B2%D0%B5%D1%82.%D0%B5%D1%81%D1%82%D1%8C+2+%D1%84%D1%83%D0%BD%D0%BA%D1%86%D0%B8%D0%B8%2Cpreg_split+%D0%B8+explode+%2C%D0%BD%D0%B5+%D0%BF%D0%BE%D0%BD%D0%B8%D0%BC%D0%B0%D1%8E%2C%D0%B2+%D1%87%D0%B5%D0%BC+%D0%BC%D0%B5%D0%B6%D0%B4%D1%83+%D0%BD%D0%B8%D0%BC%D0%B8+%D1%80%D0%B0%D0%B7%D0%BD%D0%B8%D1%86%D0%B0.'
    9     9        ASSIGN                                                   !3, '%D0%BC%D0%BD%D0%BE%D0%B3%D0%BE+%D0%B8%D1%85+%D0%B2+%D0%9F%D0%B5%D1%82%D0%B5%D1%80%D0%B1%D1%83%D1%80%D0%B3%D0%B5%2C%D0%BC%D0%BE%D0%BB%D0%BE%D0%B4%D0%B5%D0%BD%D1%8C%D0%BA%D0%B8%D1%85+%D0%B4%D1%83%D1%80%2C%D1%81%D0%B5%D0%B3%D0%BE%D0%B4%D0%BD%D1%8F+%D0%B2+%D0%B0%D1%82%D0%BB%D0%B0%D1%81%D0%B5+%D0%B4%D0%B0+%D0%B1%D0%B0%D1%80%D1%85%D0%B0%D1%82%D0%B5%2C%D0%B0+%D0%B7%D0%B0%D0%B2%D1%82%D1%80%D0%B0+%2C+%D0%BF%D0%BE%D0%B3%D0%BB%D1%8F%D0%B4%D0%B8%D1%88%D1%8C+%2C+%D0%BC%D0%B5%D1%82%D1%83%D1%82+%D1%83%D0%BB%D0%B8%D1%86%D1%83+%D0%B2%D0%BC%D0%B5%D1%81%D1%82%D0%B5+%D1%81%0A%D0%B3%D0%BE%D0%BB%D1%8C%D1%8E+%D0%BA%D0%B0%D0%B1%D0%B0%D1%86%D0%BA%D0%BE%D1%8E...%D0%B2+%D1%81%D0%B0%D0%BC%D0%BE%D0%BC+%D0%B4%D0%B5%D0%BB%D0%B5+%2C%D1%87%D1%82%D0%BE+%D0%B1%D1%8B%D0%BB%D0%BE+%D0%B1%D1%8B+%D1%81+%D0%BD%D0%B0%D0%BC%D0%B8+%2C%D0%B5%D1%81%D0%BB%D0%B8+%D0%B1%D1%8B+%D0%B2%D0%BC%D0%B5%D1%81%D1%82%D0%BE+%D0%BE%D0%B1%D1%89%D0%B5%D1%83%D0%B4%D0%BE%D0%B1%D0%BD%D0%BE%D0%B3%D0%BE+%D0%BF%D1%80%D0%B0%D0%B2%D0%B8%D0%BB%D0%B0%3A%D1%87%D0%B8%D0%BD+%D1%87%D0%B8%D0%BD%D0%B0+%D0%BF%D0%BE%D1%87%D0%B8%D1%82%D0%B0%D0%B9+%2C+%D0%B2%D0%B2%D0%B5%D0%BB%D0%BE%D1%81%D1%8C+%D0%B2%0A%D1%83%D0%BF%D0%BE%D1%82%D1%80%D0%B5%D0%B1%D0%BB%D0%B5%D0%BD%D0%B8%D0%B5+%D0%B4%D1%80%D1%83%D0%B3%D0%BE%D0%B5%2C%D0%BD%D0%B0%D0%BF%D1%80%D0%B8%D0%BC%D0%B5%D1%80%3A%D1%83%D0%BC+%D1%83%D0%BC%D0%B0+++%D0%BF%D0%BE%D1%87%D0%B8%D1%82%D0%B0%D0%B9%3F%D0%BA%D0%B0%D0%BA%D0%B8%D0%B5+%D0%B2%D0%BE%D0%B7%D0%BD%D0%B8%D0%BA%D0%BB%D0%B8++%D0%B1%D1%8B+%D1%81%D0%BF%D0%BE%D1%80%D1%8B%21'
   61    10        INIT_ARRAY                                       ~13     !0
         11        ADD_ARRAY_ELEMENT                                ~13     !1
         12        ADD_ARRAY_ELEMENT                                ~13     !2
         13        ADD_ARRAY_ELEMENT                                ~13     !3
         14        ASSIGN                                                   !4, ~13
   63    15        INIT_FCALL                                               'trim'
         16        ZEND_CALLABLE_CONVERT                            ~15     
         17        INIT_ARRAY                                       ~16     ~15
   64    18        INIT_FCALL                                               'makefirstcharinsentenceuppercase'
         19        ZEND_CALLABLE_CONVERT                            ~17     
         20        ADD_ARRAY_ELEMENT                                ~16     ~17
   65    21        INIT_FCALL                                               'rearrangespacesinsentence'
         22        ZEND_CALLABLE_CONVERT                            ~18     
         23        ADD_ARRAY_ELEMENT                                ~16     ~18
   62    24        ASSIGN                                                   !5, ~16
   68    25      > FE_RESET_R                                       $20     !4, ->34
         26    > > FE_FETCH_R                                               $20, !6, ->34
   69    27    >   INIT_FCALL                                               'fixsentencesintextbyrules'
         28        SEND_VAR                                                 !6
         29        SEND_VAR                                                 !5
         30        DO_FCALL                                      0  $21     
         31        ECHO                                                     $21
         32        ECHO                                                     '%0A'
   68    33      > JMP                                                      ->26
         34    >   FE_FREE                                                  $20
   70    35      > RETURN                                                   1

Function makefirstcharinsentenceuppercase:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/hkjXO
function name:  makeFirstCharInSentenceUpperCase
number of ops:  21
compiled vars:  !0 = $sentence, !1 = $firstChar, !2 = $remainingSentence, !3 = $upperFirstChar
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
   15     1        INIT_FCALL                                               'mb_substr'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 0
          4        SEND_VAL                                                 1
          5        DO_ICALL                                         $4      
          6        ASSIGN                                                   !1, $4
   16     7        INIT_FCALL                                               'mb_substr'
          8        SEND_VAR                                                 !0
          9        SEND_VAL                                                 1
         10        DO_ICALL                                         $6      
         11        ASSIGN                                                   !2, $6
   17    12        INIT_FCALL                                               'mb_strtoupper'
         13        SEND_VAR                                                 !1
         14        DO_ICALL                                         $8      
         15        ASSIGN                                                   !3, $8
   19    16        CONCAT                                           ~10     !3, !2
         17        VERIFY_RETURN_TYPE                                       ~10
         18      > RETURN                                                   ~10
   20    19*       VERIFY_RETURN_TYPE                                       
         20*     > RETURN                                                   null

End of function makefirstcharinsentenceuppercase

Function rearrangespacesinsentence:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 15
Branch analysis from position: 9
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/hkjXO
function name:  rearrangeSpacesInSentence
number of ops:  19
compiled vars:  !0 = $sentence, !1 = $rearrangedSentence
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   RECV                                             !0      
   30     1        INIT_FCALL                                               'preg_replace'
   31     2        SEND_VAL                                                 <array>
   32     3        SEND_VAL                                                 <array>
   33     4        SEND_VAR                                                 !0
   30     5        DO_ICALL                                         $2      
          6        ASSIGN                                                   !1, $2
   36     7        TYPE_CHECK                                    2          !1
          8      > JMPZ                                                     ~4, ->15
   37     9    >   NEW                                              $5      'RuntimeException'
         10        INIT_FCALL                                               'preg_last_error_msg'
         11        DO_ICALL                                         $6      
         12        SEND_VAR_NO_REF_EX                                       $6
         13        DO_FCALL                                      0          
         14      > THROW                                         0          $5
   40    15    >   VERIFY_RETURN_TYPE                                       !1
         16      > RETURN                                                   !1
   41    17*       VERIFY_RETURN_TYPE                                       
         18*     > RETURN                                                   null

End of function rearrangespacesinsentence

Function fixsentencesintextbyrules:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 17
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 17
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
filename:       /in/hkjXO
function name:  fixSentencesInTextByRules
number of ops:  26
compiled vars:  !0 = $text, !1 = $rules, !2 = $sentences, !3 = $rule
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   50     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   52     2        INIT_FCALL                                               'preg_split'
          3        SEND_VAL                                                 '%2F%28%3F%3C%3D%5B.%21%3F%5D%29%28%3F%3D%5B%5Cw%5Cs%5D%29%2Fu'
          4        SEND_VAR                                                 !0
          5        SEND_VAL                                                 -1
          6        SEND_VAL                                                 1
          7        DO_ICALL                                         $4      
          8        ASSIGN                                                   !2, $4
   54     9      > FE_RESET_R                                       $6      !1, ->17
         10    > > FE_FETCH_R                                               $6, !3, ->17
   55    11    >   INIT_FCALL                                               'array_map'
         12        SEND_VAR                                                 !3
         13        SEND_VAR                                                 !2
         14        DO_ICALL                                         $7      
         15        ASSIGN                                                   !2, $7
   54    16      > JMP                                                      ->10
         17    >   FE_FREE                                                  $6
   58    18        INIT_FCALL                                               'implode'
         19        SEND_VAL                                                 '+'
         20        SEND_VAR                                                 !2
         21        DO_ICALL                                         $9      
         22        VERIFY_RETURN_TYPE                                       $9
         23      > RETURN                                                   $9
   59    24*       VERIFY_RETURN_TYPE                                       
         25*     > RETURN                                                   null

End of function fixsentencesintextbyrules

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.5 ms | 1025 KiB | 26 Q