3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace Refinery29\Core; final class Util { const R29STATIC_DOMAIN = 's%d.r29static.com'; /** * @param string $text * @param string $spacer * * @return array|mixed|string */ public static function tagify($text, $spacer = '-') { //Handle if array if (is_array($text)) { return array_map("self::tagify", $text); } $text = self::decodeHtml($text); $text = self::normalizeStr($text); $text = str_replace('&', 'and', $text); return str_replace(' ', $spacer, trim(preg_replace('#([^a-z0-9/]+)#', ' ', strtolower($text)))); } /** * @param string $text * * @return string */ public static function decodeHtml($text) { return html_entity_decode($text, ENT_QUOTES, 'UTF-8'); } /** * @param string $text * * @return string */ public static function normalizeStr($text) { $map = [ 'Š' => 'S', 'š' => 's', 'Ð' => 'Dj','Ž' => 'Z', 'ž' => 'z', 'À' => 'A', 'Á' => 'A', 'Â' => 'A', 'Ã' => 'A', 'Ä' => 'A', 'Å' => 'A', 'Æ' => 'A', 'Ç' => 'C', 'È' => 'E', 'É' => 'E', 'Ê' => 'E', 'Ë' => 'E', 'Ì' => 'I', 'Í' => 'I', 'Î' => 'I', 'Ï' => 'I', 'Ñ' => 'N', 'Ò' => 'O', 'Ó' => 'O', 'Ô' => 'O', 'Õ' => 'O', 'Ö' => 'O', 'Ø' => 'O', 'Ù' => 'U', 'Ú' => 'U', 'Û' => 'U', 'Ü' => 'U', 'Ý' => 'Y', 'Þ' => 'B', 'ß' => 'Ss','à' => 'a', 'á' => 'a', 'â' => 'a', 'ã' => 'a', 'ä' => 'a', 'å' => 'a', 'æ' => 'a', 'ç' => 'c', 'è' => 'e', 'é' => 'e', 'ê' => 'e', 'ë' => 'e', 'ì' => 'i', 'í' => 'i', 'î' => 'i', 'ï' => 'i', 'ð' => 'o', 'ñ' => 'n', 'ò' => 'o', 'ó' => 'o', 'ô' => 'o', 'õ' => 'o', 'ö' => 'o', 'ø' => 'o', 'ù' => 'u', 'ú' => 'u', 'û' => 'u', 'ý' => 'y', 'ý' => 'y', 'þ' => 'b', 'ÿ' => 'y', 'ƒ' => 'f', ]; return strtr($text, $map); } /** * @param $path * @param mixed|string $app * @param string $scheme * * @return string */ public static function r29StaticAlias($path, $app = APP_NAME, $scheme = null) { // there is no bin app, bin is passed for images served by the cms if ($app === 'bin') { $path = preg_replace('#^/static/#', '/', $path); } else { $path = sprintf('%s/%s/%s', $app, rev(), $path); } $domain = sprintf(Util::R29STATIC_DOMAIN, Util::hashmod($path, 3) + 1); $url = sprintf('//%s/%s', $domain, $path); if (! empty($scheme) && strpos($url, 'http') !== 0) { $url = sprintf('%s:%s', $scheme, $url); } return $url; } /** * @param $str * @param $max * * @return int */ public static function hashmod($str, $max) { return crc32($str) % $max; } } var_dump(Refinery29\Core\Util::tagify(['sethomg john', 'yolo oko']));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TXjYB
function name:  (null)
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  100     0  E >   INIT_NS_FCALL_BY_NAME                                    'Refinery29%5CCore%5Cvar_dump'
          1        INIT_STATIC_METHOD_CALL                                  'Refinery29%5CCore%5CRefinery29%5CCore%5CUtil', 'tagify'
          2        SEND_VAL_EX                                              <array>
          3        DO_FCALL                                      0  $0      
          4        SEND_VAR_NO_REF_EX                                       $0
          5        DO_FCALL                                      0          
          6      > RETURN                                                   1

Class Refinery29\Core\Util:
Function tagify:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 11
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TXjYB
function name:  tagify
number of ops:  43
compiled vars:  !0 = $text, !1 = $spacer
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      '-'
   19     2        INIT_NS_FCALL_BY_NAME                                    'Refinery29%5CCore%5Cis_array'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0  $2      
          5      > JMPZ                                                     $2, ->11
   20     6    >   INIT_NS_FCALL_BY_NAME                                    'Refinery29%5CCore%5Carray_map'
          7        SEND_VAL_EX                                              'self%3A%3Atagify'
          8        SEND_VAR_EX                                              !0
          9        DO_FCALL                                      0  $3      
         10      > RETURN                                                   $3
   23    11    >   INIT_STATIC_METHOD_CALL                                  'decodeHtml'
         12        SEND_VAR_EX                                              !0
         13        DO_FCALL                                      0  $4      
         14        ASSIGN                                                   !0, $4
   24    15        INIT_STATIC_METHOD_CALL                                  'normalizeStr'
         16        SEND_VAR_EX                                              !0
         17        DO_FCALL                                      0  $6      
         18        ASSIGN                                                   !0, $6
   26    19        INIT_NS_FCALL_BY_NAME                                    'Refinery29%5CCore%5Cstr_replace'
         20        SEND_VAL_EX                                              '%26'
         21        SEND_VAL_EX                                              'and'
         22        SEND_VAR_EX                                              !0
         23        DO_FCALL                                      0  $8      
         24        ASSIGN                                                   !0, $8
   28    25        INIT_NS_FCALL_BY_NAME                                    'Refinery29%5CCore%5Cstr_replace'
         26        SEND_VAL_EX                                              '+'
         27        SEND_VAR_EX                                              !1
         28        INIT_NS_FCALL_BY_NAME                                    'Refinery29%5CCore%5Ctrim'
         29        INIT_NS_FCALL_BY_NAME                                    'Refinery29%5CCore%5Cpreg_replace'
         30        SEND_VAL_EX                                              '%23%28%5B%5Ea-z0-9%2F%5D%2B%29%23'
         31        SEND_VAL_EX                                              '+'
         32        INIT_NS_FCALL_BY_NAME                                    'Refinery29%5CCore%5Cstrtolower'
         33        SEND_VAR_EX                                              !0
         34        DO_FCALL                                      0  $10     
         35        SEND_VAR_NO_REF_EX                                       $10
         36        DO_FCALL                                      0  $11     
         37        SEND_VAR_NO_REF_EX                                       $11
         38        DO_FCALL                                      0  $12     
         39        SEND_VAR_NO_REF_EX                                       $12
         40        DO_FCALL                                      0  $13     
         41      > RETURN                                                   $13
   29    42*     > RETURN                                                   null

End of function tagify

Function decodehtml:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TXjYB
function name:  decodeHtml
number of ops:  9
compiled vars:  !0 = $text
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   RECV                                             !0      
   38     1        INIT_NS_FCALL_BY_NAME                                    'Refinery29%5CCore%5Chtml_entity_decode'
          2        SEND_VAR_EX                                              !0
          3        FETCH_CONSTANT                                   ~1      'Refinery29%5CCore%5CENT_QUOTES'
          4        SEND_VAL_EX                                              ~1
          5        SEND_VAL_EX                                              'UTF-8'
          6        DO_FCALL                                      0  $2      
          7      > RETURN                                                   $2
   39     8*     > RETURN                                                   null

End of function decodehtml

Function normalizestr:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TXjYB
function name:  normalizeStr
number of ops:  8
compiled vars:  !0 = $text, !1 = $map
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   46     0  E >   RECV                                             !0      
   48     1        ASSIGN                                                   !1, <array>
   58     2        INIT_NS_FCALL_BY_NAME                                    'Refinery29%5CCore%5Cstrtr'
          3        SEND_VAR_EX                                              !0
          4        SEND_VAR_EX                                              !1
          5        DO_FCALL                                      0  $3      
          6      > RETURN                                                   $3
   59     7*     > RETURN                                                   null

End of function normalizestr

Function r29staticalias:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 12
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
2 jumps found. (Code = 46) Position 1 = 40, Position 2 = 46
Branch analysis from position: 40
2 jumps found. (Code = 43) Position 1 = 47, Position 2 = 53
Branch analysis from position: 47
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 53
Branch analysis from position: 46
Branch analysis from position: 12
2 jumps found. (Code = 46) Position 1 = 40, Position 2 = 46
Branch analysis from position: 40
Branch analysis from position: 46
filename:       /in/TXjYB
function name:  r29StaticAlias
number of ops:  55
compiled vars:  !0 = $path, !1 = $app, !2 = $scheme, !3 = $domain, !4 = $url
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   68     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <const ast>
          2        RECV_INIT                                        !2      null
   72     3        IS_IDENTICAL                                             !1, 'bin'
          4      > JMPZ                                                     ~5, ->12
   73     5    >   INIT_NS_FCALL_BY_NAME                                    'Refinery29%5CCore%5Cpreg_replace'
          6        SEND_VAL_EX                                              '%23%5E%2Fstatic%2F%23'
          7        SEND_VAL_EX                                              '%2F'
          8        SEND_VAR_EX                                              !0
          9        DO_FCALL                                      0  $6      
         10        ASSIGN                                                   !0, $6
         11      > JMP                                                      ->21
   75    12    >   INIT_NS_FCALL_BY_NAME                                    'Refinery29%5CCore%5Csprintf'
         13        SEND_VAL_EX                                              '%25s%2F%25s%2F%25s'
         14        SEND_VAR_EX                                              !1
         15        INIT_NS_FCALL_BY_NAME                                    'Refinery29%5CCore%5Crev'
         16        DO_FCALL                                      0  $8      
         17        SEND_VAR_NO_REF_EX                                       $8
         18        SEND_VAR_EX                                              !0
         19        DO_FCALL                                      0  $9      
         20        ASSIGN                                                   !0, $9
   78    21    >   INIT_NS_FCALL_BY_NAME                                    'Refinery29%5CCore%5Csprintf'
         22        SEND_VAL_EX                                              's%25d.r29static.com'
         23        INIT_STATIC_METHOD_CALL                                  'Refinery29%5CCore%5CUtil', 'hashmod'
         24        SEND_VAR_EX                                              !0
         25        SEND_VAL_EX                                              3
         26        DO_FCALL                                      0  $11     
         27        ADD                                              ~12     $11, 1
         28        SEND_VAL_EX                                              ~12
         29        DO_FCALL                                      0  $13     
         30        ASSIGN                                                   !3, $13
   79    31        INIT_NS_FCALL_BY_NAME                                    'Refinery29%5CCore%5Csprintf'
         32        SEND_VAL_EX                                              '%2F%2F%25s%2F%25s'
         33        SEND_VAR_EX                                              !3
         34        SEND_VAR_EX                                              !0
         35        DO_FCALL                                      0  $15     
         36        ASSIGN                                                   !4, $15
   81    37        ISSET_ISEMPTY_CV                                 ~17     !2
         38        BOOL_NOT                                         ~18     ~17
         39      > JMPZ_EX                                          ~18     ~18, ->46
         40    >   INIT_NS_FCALL_BY_NAME                                    'Refinery29%5CCore%5Cstrpos'
         41        SEND_VAR_EX                                              !4
         42        SEND_VAL_EX                                              'http'
         43        DO_FCALL                                      0  $19     
         44        IS_NOT_IDENTICAL                                 ~20     $19, 0
         45        BOOL                                             ~18     ~20
         46    > > JMPZ                                                     ~18, ->53
   82    47    >   INIT_NS_FCALL_BY_NAME                                    'Refinery29%5CCore%5Csprintf'
         48        SEND_VAL_EX                                              '%25s%3A%25s'
         49        SEND_VAR_EX                                              !2
         50        SEND_VAR_EX                                              !4
         51        DO_FCALL                                      0  $21     
         52        ASSIGN                                                   !4, $21
   85    53    > > RETURN                                                   !4
   86    54*     > RETURN                                                   null

End of function r29staticalias

Function hashmod:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TXjYB
function name:  hashmod
number of ops:  8
compiled vars:  !0 = $str, !1 = $max
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   94     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   96     2        INIT_NS_FCALL_BY_NAME                                    'Refinery29%5CCore%5Ccrc32'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0  $2      
          5        MOD                                              ~3      $2, !1
          6      > RETURN                                                   ~3
   97     7*     > RETURN                                                   null

End of function hashmod

End of class Refinery29\Core\Util.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
173.48 ms | 1411 KiB | 38 Q