3v4l.org

run code in 500+ PHP versions simultaneously
<?php error_reporting(-1); mb_internal_encoding('utf-8'); //$text = "Кажется, нас обнаружили! Надо срочно уходить отсюда, пока не поздно. Бежим же скорее!"; // Другие варианты для тестов //$text = "Ну, прости меня! Не хотела я тебе зла сделать; да в себе не вольна была. Что говорила, что делала, себя не помнила."; $text = "Идет гражданская война. Космические корабли повстанцев, наносящие удар с тайной базы, одержали первую победу, в схватке со зловещей Галактической Империей."; /* Делает первую букву предложения заглавной */ function makeFirstletterUppercase($text) { $second = 1; $first = mb_substr($text, 0, $second); //проверяем, чтобы первый символ был не пробелом{ if ($first == ' '){ $second = 2; $first = mb_substr($text, 0, $second); } //} $other = mb_substr($text, $second); $first = mb_strtoupper($first); $text = $first . $other; return $text; } function makeYodaStyleText($text) { //разбили текст на предложения и записали в массив { $regexp = '/[\\.\\?\\!]/ui'; $parts = preg_split($regexp, $text, 0, PREG_SPLIT_NO_EMPTY); //} $text = ""; //регулярка для разбива на отдельные слова { $regexp = '/[,;]* /ui'; //} foreach ($parts as $part){ //делаем все буквы в предложении маленькими и бъем по словам { $part = mb_strtolower($part); $words = preg_split($regexp, $part, 0, PREG_SPLIT_NO_EMPTY); //} //var_dump($words); $words = array_reverse($words); //var_dump($words); $string = implode(" ", $words); $string = $string . ". "; $text = $text . makeFirstletterUppercase($string); } return $text; } $yodaText = makeYodaStyleText($text); echo "Йода говорит: {$yodaText}\n";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/p5od8
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                                                     
    9     6        ASSIGN                                                       !0, '%D0%98%D0%B4%D0%B5%D1%82+%D0%B3%D1%80%D0%B0%D0%B6%D0%B4%D0%B0%D0%BD%D1%81%D0%BA%D0%B0%D1%8F+%D0%B2%D0%BE%D0%B9%D0%BD%D0%B0.+%D0%9A%D0%BE%D1%81%D0%BC%D0%B8%D1%87%D0%B5%D1%81%D0%BA%D0%B8%D0%B5+%D0%BA%D0%BE%D1%80%D0%B0%D0%B1%D0%BB%D0%B8+%D0%BF%D0%BE%D0%B2%D1%81%D1%82%D0%B0%D0%BD%D1%86%D0%B5%D0%B2%2C+%D0%BD%D0%B0%D0%BD%D0%BE%D1%81%D1%8F%D1%89%D0%B8%D0%B5+%D1%83%D0%B4%D0%B0%D1%80+%D1%81+%D1%82%D0%B0%D0%B9%D0%BD%D0%BE%D0%B9+%D0%B1%D0%B0%D0%B7%D1%8B%2C+%D0%BE%D0%B4%D0%B5%D1%80%D0%B6%D0%B0%D0%BB%D0%B8+%D0%BF%D0%B5%D1%80%D0%B2%D1%83%D1%8E+%D0%BF%D0%BE%D0%B1%D0%B5%D0%B4%D1%83%2C+%D0%B2+%D1%81%D1%85%D0%B2%D0%B0%D1%82%D0%BA%D0%B5+%D1%81%D0%BE+%D0%B7%D0%BB%D0%BE%D0%B2%D0%B5%D1%89%D0%B5%D0%B9+%D0%93%D0%B0%D0%BB%D0%B0%D0%BA%D1%82%D0%B8%D1%87%D0%B5%D1%81%D0%BA%D0%BE%D0%B9+%D0%98%D0%BC%D0%BF%D0%B5%D1%80%D0%B8%D0%B5%D0%B9.'
   51     7        INIT_FCALL                                                   'makeyodastyletext'
          8        SEND_VAR                                                     !0
          9        DO_FCALL                                          0  $5      
         10        ASSIGN                                                       !1, $5
   52    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
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 17
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
filename:       /in/p5od8
function name:  makeFirstletterUppercase
number of ops:  30
compiled vars:  !0 = $text, !1 = $second, !2 = $first, !3 = $other
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   12     0  E >   RECV                                                 !0      
   13     1        ASSIGN                                                       !1, 1
   14     2        INIT_FCALL                                                   'mb_substr'
          3        SEND_VAR                                                     !0
          4        SEND_VAL                                                     0
          5        SEND_VAR                                                     !1
          6        DO_ICALL                                             $5      
          7        ASSIGN                                                       !2, $5
   16     8        IS_EQUAL                                                     !2, '+'
          9      > JMPZ                                                         ~7, ->17
   17    10    >   ASSIGN                                                       !1, 2
   18    11        INIT_FCALL                                                   'mb_substr'
         12        SEND_VAR                                                     !0
         13        SEND_VAL                                                     0
         14        SEND_VAR                                                     !1
         15        DO_ICALL                                             $9      
         16        ASSIGN                                                       !2, $9
   21    17    >   INIT_FCALL                                                   'mb_substr'
         18        SEND_VAR                                                     !0
         19        SEND_VAR                                                     !1
         20        DO_ICALL                                             $11     
         21        ASSIGN                                                       !3, $11
   22    22        INIT_FCALL                                                   'mb_strtoupper'
         23        SEND_VAR                                                     !2
         24        DO_ICALL                                             $13     
         25        ASSIGN                                                       !2, $13
   23    26        CONCAT                                               ~15     !2, !3
         27        ASSIGN                                                       !0, ~15
   24    28      > RETURN                                                       !0
   25    29*     > RETURN                                                       null

End of function makefirstletteruppercase

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

End of function makeyodastyletext

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
177.53 ms | 2134 KiB | 22 Q