3v4l.org

run code in 300+ PHP versions simultaneously
<?php function translit($string){ $rus = array("/а/", "/б/", "/в/", "/г/", "/ґ/", "/д/", "/е/", "/ё/", "/ж/", "/з/", "/и/", "/й/", "/к/", "/л/", "/м/", "/н/", "/о/", "/п/", "/р/", "/с/", "/т/", "/у/", "/ф/", "/х/", "/ц/", "/ч/", "/ш/", "/щ/", "/ы/", "/э/", "/ю/", "/я/", "/ь/", "/ъ/", "/і/", "/ї/", "/є/", "/А/", "/Б/", "/В/", "/Г/", "/ґ/", "/Д/", "/Е/", "/Ё/", "/Ж/", "/З/", "/И/", "/Й/", "/К/", "/Л/", "/М/", "/Н/", "/О/", "/П/", "/Р/", "/С/", "/Т/", "/У/", "/Ф/", "/Х/", "/Ц/", "/Ч/", "/Ш/", "/Щ/", "/Ы/", "/Э/", "/Ю/", "/Я/", "/Ь/", "/Ъ/", "/І/", "/Ї/", "/Є/"); $lat = array("a", "b", "v", "g", "g", "d", "e", "e", "zh", "z", "i", "j", "k", "l", "m", "n", "o", "p", "r", "s", "t", "u", "f", "h", "c", "ch", "sh", "sh'", "y", "e", "yu", "ya", "'", "'", "i", "i", "e", "A", "B", "V", "G", "G", "D", "E", "E", "ZH", "Z", "I", "J", "K", "L", "M", "N", "O", "P", "R", "S", "T", "U", "F", "H", "C", "CH", "SH", "SH'", "Y", "E", "YU", "YA", "'", "'", "I", "I", "E"); return preg_replace($rus, $lat, $string); } function slugify($text) { // replace non letter or digits by - $text = preg_replace('~[^\\pL\d]+~u', '-', $text); // trim $text = trim($text, '-'); // transliterate $text = translit($text); echo $text . "\n"; // lowercase $text = strtolower($text); // remove unwanted characters $text = preg_replace('~[^-\w]+~', '', $text); if (empty($text)) { return 'n-a'; } return $text; } echo slugify('Тестовый пример');
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ELZ6V
function name:  (null)
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   60     0  E >   INIT_FCALL                                               'slugify'
          1        SEND_VAL                                                 '%D0%A2%D0%B5%D1%81%D1%82%D0%BE%D0%B2%D1%8B%D0%B9+%D0%BF%D1%80%D0%B8%D0%BC%D0%B5%D1%80'
          2        DO_FCALL                                      0  $0      
          3        ECHO                                                     $0
          4      > RETURN                                                   1

Function translit:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ELZ6V
function name:  translit
number of ops:  10
compiled vars:  !0 = $string, !1 = $rus, !2 = $lat
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
    5     1        ASSIGN                                                   !1, <array>
   18     2        ASSIGN                                                   !2, <array>
   28     3        INIT_FCALL                                               'preg_replace'
          4        SEND_VAR                                                 !1
          5        SEND_VAR                                                 !2
          6        SEND_VAR                                                 !0
          7        DO_ICALL                                         $5      
          8      > RETURN                                                   $5
   29     9*     > RETURN                                                   null

End of function translit

Function slugify:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 30, Position 2 = 31
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ELZ6V
function name:  slugify
number of ops:  33
compiled vars:  !0 = $text
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   RECV                                             !0      
   35     1        INIT_FCALL                                               'preg_replace'
          2        SEND_VAL                                                 '%7E%5B%5E%5CpL%5Cd%5D%2B%7Eu'
          3        SEND_VAL                                                 '-'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $1      
          6        ASSIGN                                                   !0, $1
   39     7        INIT_FCALL                                               'trim'
          8        SEND_VAR                                                 !0
          9        SEND_VAL                                                 '-'
         10        DO_ICALL                                         $3      
         11        ASSIGN                                                   !0, $3
   42    12        INIT_FCALL                                               'translit'
         13        SEND_VAR                                                 !0
         14        DO_FCALL                                      0  $5      
         15        ASSIGN                                                   !0, $5
   43    16        CONCAT                                           ~7      !0, '%0A'
         17        ECHO                                                     ~7
   46    18        INIT_FCALL                                               'strtolower'
         19        SEND_VAR                                                 !0
         20        DO_ICALL                                         $8      
         21        ASSIGN                                                   !0, $8
   49    22        INIT_FCALL                                               'preg_replace'
         23        SEND_VAL                                                 '%7E%5B%5E-%5Cw%5D%2B%7E'
         24        SEND_VAL                                                 ''
         25        SEND_VAR                                                 !0
         26        DO_ICALL                                         $10     
         27        ASSIGN                                                   !0, $10
   51    28        ISSET_ISEMPTY_CV                                         !0
         29      > JMPZ                                                     ~12, ->31
   53    30    > > RETURN                                                   'n-a'
   56    31    > > RETURN                                                   !0
   57    32*     > RETURN                                                   null

End of function slugify

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.61 ms | 1403 KiB | 21 Q