3v4l.org

run code in 500+ PHP versions simultaneously
<?php error_reporting(-1); mb_internal_encoding('utf-8'); $text = "Кажется, нас обнаружили! Надо срочно уходить отсюда, пока не поздно. Бежим же скорее!"; // Другие варианты для тестов // $text = "Ну, прости меня! Не хотела я тебе зла сделать; да в себе не вольна была. Что говорила, что делала, себя не помнила."; // $text = "Идет гражданская война. Космические корабли повстанцев, наносящие удар с тайной базы, одержали первую победу, в схватке со зловещей Галактической Империей."; //добавляем пробел перед первым словом, для того чтобы первое слово не слипалось при implode //$text1=" "; $text1.=$text; $text=$text1; /* Делает первую букву предложения заглавной */ function makeFirstletterUppercase($text) { $text = mb_strtoupper(mb_substr($text, 0, 1)) . mb_substr($text, 1, NULL); return $text; } function makeYodaStyleText($text) { $text = mb_strtolower($text); $text = preg_replace('[,]', "", $text); $text = preg_split('/(?<=[!\?\.])/u', $text, -1, PREG_SPLIT_NO_EMPTY); echo " дамп : "; var_dump($text); $words = " "; foreach ($text as $word) { $word = explode(' ', $word); echo " \n\n "; echo " дамп word: "; var_dump($word); echo " \n\n "; $word = implode(" ", array_reverse($word)); $word = preg_replace("[!]", "", $word); $word = preg_replace("[\.]", "", $word); $word .= "."; //делаем большой буква первый $word = makeFirstletterUppercase($word); //единение текстов $words .= $word; echo " дамп реверс word: "; echo $word; } echo "\n финал : "; echo $words; return $words; // $result = ''; /* Сделай сам */ } $yodaText = makeYodaStyleText($text); $yodaText = preg_replace('/\s*([,.;:!?])\s*(\w+)/ui', '$1 $2', $yodaText); echo "\n\nЙода говорит: {$yodaText}\n";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/debbd
function name:  (null)
number of ops:  19
compiled vars:  !0 = $text, !1 = $yodaText
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%9A%D0%B0%D0%B6%D0%B5%D1%82%D1%81%D1%8F%2C+%D0%BD%D0%B0%D1%81+%D0%BE%D0%B1%D0%BD%D0%B0%D1%80%D1%83%D0%B6%D0%B8%D0%BB%D0%B8%21+%D0%9D%D0%B0%D0%B4%D0%BE+%D1%81%D1%80%D0%BE%D1%87%D0%BD%D0%BE+%D1%83%D1%85%D0%BE%D0%B4%D0%B8%D1%82%D1%8C+%D0%BE%D1%82%D1%81%D1%8E%D0%B4%D0%B0%2C+%D0%BF%D0%BE%D0%BA%D0%B0+%D0%BD%D0%B5+%D0%BF%D0%BE%D0%B7%D0%B4%D0%BD%D0%BE.+%D0%91%D0%B5%D0%B6%D0%B8%D0%BC+%D0%B6%D0%B5+%D1%81%D0%BA%D0%BE%D1%80%D0%B5%D0%B5%21'
   64     7        INIT_FCALL                                                   'makeyodastyletext'
          8        SEND_VAR                                                     !0
          9        DO_FCALL                                          0  $5      
         10        ASSIGN                                                       !1, $5
   65    11        FRAMELESS_ICALL_3                preg_replace        ~7      '%2F%5Cs%2A%28%5B%2C.%3B%3A%21%3F%5D%29%5Cs%2A%28%5Cw%2B%29%2Fui', '%241+%242'
         12        OP_DATA                                                      !1
         13        ASSIGN                                                       !1, ~7
   66    14        ROPE_INIT                                         3  ~10     '%0A%0A%D0%99%D0%BE%D0%B4%D0%B0+%D0%B3%D0%BE%D0%B2%D0%BE%D1%80%D0%B8%D1%82%3A+'
         15        ROPE_ADD                                          1  ~10     ~10, !1
         16        ROPE_END                                          2  ~9      ~10, '%0A'
         17        ECHO                                                         ~9
         18      > RETURN                                                       1

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

End of function makefirstletteruppercase

Function makeyodastyletext:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 21, Position 2 = 53
Branch analysis from position: 21
2 jumps found. (Code = 78) Position 1 = 22, Position 2 = 53
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
Branch analysis from position: 53
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 53
filename:       /in/debbd
function name:  makeYodaStyleText
number of ops:  58
compiled vars:  !0 = $text, !1 = $words, !2 = $word
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   22     0  E >   RECV                                                 !0      
   24     1        INIT_FCALL                                                   'mb_strtolower'
          2        SEND_VAR                                                     !0
          3        DO_ICALL                                             $3      
          4        ASSIGN                                                       !0, $3
   25     5        FRAMELESS_ICALL_3                preg_replace        ~5      '%5B%2C%5D', ''
          6        OP_DATA                                                      !0
          7        ASSIGN                                                       !0, ~5
   26     8        INIT_FCALL                                                   'preg_split'
          9        SEND_VAL                                                     '%2F%28%3F%3C%3D%5B%21%5C%3F%5C.%5D%29%2Fu'
         10        SEND_VAR                                                     !0
         11        SEND_VAL                                                     -1
         12        SEND_VAL                                                     1
         13        DO_ICALL                                             $7      
         14        ASSIGN                                                       !0, $7
   27    15        ECHO                                                         '+%D0%B4%D0%B0%D0%BC%D0%BF+%3A+'
   28    16        INIT_FCALL                                                   'var_dump'
         17        SEND_VAR                                                     !0
         18        DO_ICALL                                                     
   30    19        ASSIGN                                                       !1, '+'
   32    20      > FE_RESET_R                                           $11     !0, ->53
         21    > > FE_FETCH_R                                                   $11, !2, ->53
   33    22    >   INIT_FCALL                                                   'explode'
         23        SEND_VAL                                                     '+'
         24        SEND_VAR                                                     !2
         25        DO_ICALL                                             $12     
         26        ASSIGN                                                       !2, $12
   35    27        ECHO                                                         '+%0A%0A+'
   36    28        ECHO                                                         '+%D0%B4%D0%B0%D0%BC%D0%BF+word%3A+'
   37    29        INIT_FCALL                                                   'var_dump'
         30        SEND_VAR                                                     !2
         31        DO_ICALL                                                     
   38    32        ECHO                                                         '+%0A%0A+'
   40    33        INIT_FCALL                                                   'array_reverse'
         34        SEND_VAR                                                     !2
         35        DO_ICALL                                             $15     
         36        FRAMELESS_ICALL_2                implode             ~16     '+', $15
         37        ASSIGN                                                       !2, ~16
   44    38        FRAMELESS_ICALL_3                preg_replace        ~18     '%5B%21%5D', ''
         39        OP_DATA                                                      !2
         40        ASSIGN                                                       !2, ~18
   45    41        FRAMELESS_ICALL_3                preg_replace        ~20     '%5B%5C.%5D', ''
         42        OP_DATA                                                      !2
         43        ASSIGN                                                       !2, ~20
   46    44        ASSIGN_OP                                         8          !2, '.'
   48    45        INIT_FCALL                                                   'makefirstletteruppercase'
         46        SEND_VAR                                                     !2
         47        DO_FCALL                                          0  $23     
         48        ASSIGN                                                       !2, $23
   50    49        ASSIGN_OP                                         8          !1, !2
   51    50        ECHO                                                         '+%D0%B4%D0%B0%D0%BC%D0%BF+%D1%80%D0%B5%D0%B2%D0%B5%D1%80%D1%81+word%3A+'
   52    51        ECHO                                                         !2
   32    52      > JMP                                                          ->21
         53    >   FE_FREE                                                      $11
   54    54        ECHO                                                         '%0A+%D1%84%D0%B8%D0%BD%D0%B0%D0%BB+%3A+'
   55    55        ECHO                                                         !1
   58    56      > RETURN                                                       !1
   62    57*     > RETURN                                                       null

End of function makeyodastyletext

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
179.46 ms | 2467 KiB | 24 Q