3v4l.org

run code in 300+ PHP versions simultaneously
<?php error_reporting(-1); mb_internal_encoding('utf-8'); $text = "Кажется, нас обнаружили! Надо срочно уходить отсюда, пока не поздно. Бежим же скорее!"; // Другие варианты для тестов // $text = "Ну, прости меня! Не хотела я тебе зла сделать; да в себе не вольна была. Что говорила, что делала, себя не помнила."; // $text = "Идет гражданская война. Космические корабли повстанцев, наносящие удар с тайной базы, одержали первую победу, в схватке со зловещей Галактической Империей."; /* Делает первую букву предложения заглавной */ function makeFirstletterUppercase($text) { return mb_strtoupper(mb_substr($text, 0, 1)).mb_substr($text, 1); } function makeYodaStyleText($text) { $parts = preg_split('/[.|!|?|;][ ]?/ui', $text); foreach ($parts as &$part) { $words = preg_split('/[,]?[ ]/', $part); $words[0] = mb_strtolower($words[0]); $words = array_reverse($words); $words[0] = makeFirstletterUppercase($words[0]); $part = implode(" ", $words); } return implode(". ", $parts); } $yodaText = makeYodaStyleText($text); echo "Йода говорит: {$yodaText}\n";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/coKeP
function name:  (null)
number of ops:  16
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'
   30     7        INIT_FCALL                                               'makeyodastyletext'
          8        SEND_VAR                                                 !0
          9        DO_FCALL                                      0  $5      
         10        ASSIGN                                                   !1, $5
   31    11        ROPE_INIT                                     3  ~8      '%D0%99%D0%BE%D0%B4%D0%B0+%D0%B3%D0%BE%D0%B2%D0%BE%D1%80%D0%B8%D1%82%3A+'
         12        ROPE_ADD                                      1  ~8      ~8, !1
         13        ROPE_END                                      2  ~7      ~8, '%0A'
         14        ECHO                                                     ~7
         15      > RETURN                                                   1

Function makefirstletteruppercase:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/coKeP
function name:  makeFirstletterUppercase
number of ops:  16
compiled vars:  !0 = $text
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
   13     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        DO_ICALL                                         $3      
         13        CONCAT                                           ~4      $2, $3
         14      > RETURN                                                   ~4
   14    15*     > RETURN                                                   null

End of function makefirstletteruppercase

Function makeyodastyletext:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 125) Position 1 = 7, Position 2 = 35
Branch analysis from position: 7
2 jumps found. (Code = 126) Position 1 = 8, Position 2 = 35
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 35
filename:       /in/coKeP
function name:  makeYodaStyleText
number of ops:  42
compiled vars:  !0 = $text, !1 = $parts, !2 = $part, !3 = $words
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
   17     1        INIT_FCALL                                               'preg_split'
          2        SEND_VAL                                                 '%2F%5B.%7C%21%7C%3F%7C%3B%5D%5B+%5D%3F%2Fui'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $4      
          5        ASSIGN                                                   !1, $4
   19     6      > FE_RESET_RW                                      $6      !1, ->35
          7    > > FE_FETCH_RW                                              $6, !2, ->35
   20     8    >   INIT_FCALL                                               'preg_split'
          9        SEND_VAL                                                 '%2F%5B%2C%5D%3F%5B+%5D%2F'
         10        SEND_VAR                                                 !2
         11        DO_ICALL                                         $7      
         12        ASSIGN                                                   !3, $7
   21    13        INIT_FCALL                                               'mb_strtolower'
         14        FETCH_DIM_R                                      ~10     !3, 0
         15        SEND_VAL                                                 ~10
         16        DO_ICALL                                         $11     
         17        ASSIGN_DIM                                               !3, 0
         18        OP_DATA                                                  $11
   22    19        INIT_FCALL                                               'array_reverse'
         20        SEND_VAR                                                 !3
         21        DO_ICALL                                         $12     
         22        ASSIGN                                                   !3, $12
   23    23        INIT_FCALL                                               'makefirstletteruppercase'
         24        FETCH_DIM_R                                      ~15     !3, 0
         25        SEND_VAL                                                 ~15
         26        DO_FCALL                                      0  $16     
         27        ASSIGN_DIM                                               !3, 0
         28        OP_DATA                                                  $16
   24    29        INIT_FCALL                                               'implode'
         30        SEND_VAL                                                 '+'
         31        SEND_VAR                                                 !3
         32        DO_ICALL                                         $17     
         33        ASSIGN                                                   !2, $17
   19    34      > JMP                                                      ->7
         35    >   FE_FREE                                                  $6
   27    36        INIT_FCALL                                               'implode'
         37        SEND_VAL                                                 '.+'
         38        SEND_VAR                                                 !1
         39        DO_ICALL                                         $19     
         40      > RETURN                                                   $19
   28    41*     > RETURN                                                   null

End of function makeyodastyletext

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
143.55 ms | 1411 KiB | 31 Q