3v4l.org

run code in 500+ PHP versions simultaneously
<?php function generateKeywordsFromText($text){ // List of words NOT to be included in keywords $stopWords = array('à','à demi','à peine','à peu près','absolument','actuellement','ainsi','alors','apparemment','approximativement','après','après-demain','assez','assurément','au','aucun','aucunement','aucuns','aujourd\'hui','auparavant','aussi','aussitôt','autant','autre','autrefois','autrement','avant','avant-hier','avec','avoir','beaucoup','bien','bientôt','bon','c\'','ça','car','carrément','ce','cela','cependant','certainement','certes','ces','ceux','chaque','ci','comme','comment','complètement','d\'','d\'abord','dans','davantage','de','début','dedans','dehors','déjà','demain','depuis','derechef','des','désormais','deux','devrait','diablement','divinement','doit','donc','dorénavant','dos','droite','drôlement','du','elle','elles','en','en vérité','encore','enfin','ensuite','entièrement','entre-temps','environ','essai','est','et','étaient','état','été','étions','être','eu','extrêmement','fait','faites','fois','font','force','grandement','guère','habituellement','haut','hier','hors','ici','il','ils','infiniment','insuffisamment','jadis','jamais','je','joliment','ka','la','là','le','les','leur','leurs','lol','longtemps','lors','ma','maintenant','mais','mdr','même','mes','moins','mon','mot','naguère','ne','ni','nommés','non','notre','nous','nouveaux','nullement','ou','où','oui','par','parce','parfois','parole','pas','pas mal','passablement','personne','personnes','peu','peut','peut-être','pièce','plupart','plus','plutôt','point','pour','pourquoi','précisément','premièrement','presque','probablement','prou','puis','quand','quasi','quasiment','que','quel','quelle','quelles','quelque','quelquefois','quels','qui','quoi','quotidiennement','rien','rudement','s\'','sa','sans','sans doute','ses','seulement','si','sien','sitôt','soit','son','sont','soudain','sous','souvent','soyez','subitement','suffisamment','sur','t\'','ta','tandis','tant','tantôt','tard','tellement','tellement','tels','terriblement','tes','ton','tôt','totalement','toujours','tous','tout','tout à fait','toutefois','très','trop','tu','un','une','valeur','vers','voie','voient','volontiers','vont','votre','vous','vraiment','vraisemblablement'); //Let us do some basic clean up! on the text before getting to real keyword generation work $text = preg_replace('/\s{2,}/ui', '', $text); // replace multiple spaces etc. in the text $text = trim($text); // trim any extra spaces at start or end of the text $text = preg_replace('/[^\p{L}0-9 .-]+/u', '', $text); // only take alphanumerical characters, but keep the spaces and dashes too… $text = strtolower($text); // Make the text lowercase so that output is in lowercase and whole operation is case in sensitive. // Find all words preg_match_all('/\w+/iu', $text, $allTheWords); $allTheWords = $allTheWords[0]; //Now loop through the whole list and remove smaller or empty words foreach ( $allTheWords as $key=>$item ) { if ( $item == '' || in_array(strtolower($item), $stopWords) || strlen($item) <= 3 ) { unset($allTheWords[$key]); } } // Create array that will later have its index as keyword and value as keyword count. $wordCountArr = array(); // Now populate this array with keywrds and the occurance count if ( is_array($allTheWords) ) { foreach ( $allTheWords as $key => $val ) { $val = strtolower($val); if ( isset($wordCountArr[$val]) ) { $wordCountArr[$val]++; } else { $wordCountArr[$val] = 1; } } } // Sort array by the number of repetitions arsort($wordCountArr); //Keep first 10 keywords, throw other keywords $wordCountArr = array_slice($wordCountArr, 0, 10); // Now generate comma separated list from the array $words=""; foreach ($wordCountArr as $key=>$value) $words .= " " . $key ; // Trim list of comma separated keyword list and return the list return trim($words," "); } echo $contentkeywords = generateKeywordsFromText("Hello Héllo");
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jdhDi
function name:  (null)
number of ops:  6
compiled vars:  !0 = $contentkeywords
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   58     0  E >   INIT_FCALL                                                   'generatekeywordsfromtext'
          1        SEND_VAL                                                     'Hello+H%C3%A9llo'
          2        DO_FCALL                                          0  $1      
          3        ASSIGN                                               ~2      !0, $1
          4        ECHO                                                         ~2
          5      > RETURN                                                       1

Function generatekeywordsfromtext:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 22, Position 2 = 38
Branch analysis from position: 22
2 jumps found. (Code = 78) Position 1 = 23, Position 2 = 38
Branch analysis from position: 23
2 jumps found. (Code = 47) Position 1 = 26, Position 2 = 31
Branch analysis from position: 26
2 jumps found. (Code = 47) Position 1 = 32, Position 2 = 35
Branch analysis from position: 32
2 jumps found. (Code = 43) Position 1 = 36, Position 2 = 37
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
Branch analysis from position: 37
Branch analysis from position: 35
Branch analysis from position: 31
Branch analysis from position: 38
2 jumps found. (Code = 43) Position 1 = 42, Position 2 = 58
Branch analysis from position: 42
2 jumps found. (Code = 77) Position 1 = 43, Position 2 = 57
Branch analysis from position: 43
2 jumps found. (Code = 78) Position 1 = 44, Position 2 = 57
Branch analysis from position: 44
2 jumps found. (Code = 43) Position 1 = 51, Position 2 = 54
Branch analysis from position: 51
1 jumps found. (Code = 42) Position 1 = 56
Branch analysis from position: 56
1 jumps found. (Code = 42) Position 1 = 43
Branch analysis from position: 43
Branch analysis from position: 54
1 jumps found. (Code = 42) Position 1 = 43
Branch analysis from position: 43
Branch analysis from position: 57
2 jumps found. (Code = 77) Position 1 = 69, Position 2 = 74
Branch analysis from position: 69
2 jumps found. (Code = 78) Position 1 = 70, Position 2 = 74
Branch analysis from position: 70
1 jumps found. (Code = 42) Position 1 = 69
Branch analysis from position: 69
Branch analysis from position: 74
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 74
Branch analysis from position: 57
Branch analysis from position: 58
Branch analysis from position: 38
filename:       /in/jdhDi
function name:  generateKeywordsFromText
number of ops:  78
compiled vars:  !0 = $text, !1 = $stopWords, !2 = $allTheWords, !3 = $item, !4 = $key, !5 = $wordCountArr, !6 = $val, !7 = $words, !8 = $value
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   RECV                                                 !0      
    7     1        ASSIGN                                                       !1, <array>
   11     2        FRAMELESS_ICALL_3                preg_replace        ~10     '%2F%5Cs%7B2%2C%7D%2Fui', ''
          3        OP_DATA                                                      !0
          4        ASSIGN                                                       !0, ~10
   12     5        FRAMELESS_ICALL_1                trim                ~12     !0
          6        ASSIGN                                                       !0, ~12
   13     7        FRAMELESS_ICALL_3                preg_replace        ~14     '%2F%5B%5E%5Cp%7BL%7D0-9+.-%5D%2B%2Fu', ''
          8        OP_DATA                                                      !0
          9        ASSIGN                                                       !0, ~14
   14    10        INIT_FCALL                                                   'strtolower'
         11        SEND_VAR                                                     !0
         12        DO_ICALL                                             $16     
         13        ASSIGN                                                       !0, $16
   17    14        INIT_FCALL                                                   'preg_match_all'
         15        SEND_VAL                                                     '%2F%5Cw%2B%2Fiu'
         16        SEND_VAR                                                     !0
         17        SEND_REF                                                     !2
         18        DO_ICALL                                                     
   18    19        FETCH_DIM_R                                          ~19     !2, 0
         20        ASSIGN                                                       !2, ~19
   21    21      > FE_RESET_R                                           $21     !2, ->38
         22    > > FE_FETCH_R                                           ~22     $21, !3, ->38
         23    >   ASSIGN                                                       !4, ~22
   23    24        IS_EQUAL                                             ~24     !3, ''
         25      > JMPNZ_EX                                             ~24     ~24, ->31
         26    >   INIT_FCALL                                                   'strtolower'
         27        SEND_VAR                                                     !3
         28        DO_ICALL                                             $25     
         29        FRAMELESS_ICALL_2                in_array            ~26     $25, !1
         30        BOOL                                                 ~24     ~26
         31    > > JMPNZ_EX                                             ~24     ~24, ->35
         32    >   STRLEN                                               ~27     !3
         33        IS_SMALLER_OR_EQUAL                                  ~28     ~27, 3
         34        BOOL                                                 ~24     ~28
         35    > > JMPZ                                                         ~24, ->37
   24    36    >   UNSET_DIM                                                    !2, !4
   21    37    > > JMP                                                          ->22
         38    >   FE_FREE                                                      $21
   29    39        ASSIGN                                                       !5, <array>
   32    40        TYPE_CHECK                                      128          !2
         41      > JMPZ                                                         ~30, ->58
   33    42    > > FE_RESET_R                                           $31     !2, ->57
         43    > > FE_FETCH_R                                           ~32     $31, !6, ->57
         44    >   ASSIGN                                                       !4, ~32
   34    45        INIT_FCALL                                                   'strtolower'
         46        SEND_VAR                                                     !6
         47        DO_ICALL                                             $34     
         48        ASSIGN                                                       !6, $34
   35    49        ISSET_ISEMPTY_DIM_OBJ                             0          !5, !6
         50      > JMPZ                                                         ~36, ->54
   36    51    >   FETCH_DIM_RW                                         $37     !5, !6
         52        PRE_INC                                                      $37
   35    53      > JMP                                                          ->56
   38    54    >   ASSIGN_DIM                                                   !5, !6
         55        OP_DATA                                                      1
   33    56    > > JMP                                                          ->43
         57    >   FE_FREE                                                      $31
   44    58    >   INIT_FCALL                                                   'arsort'
         59        SEND_REF                                                     !5
         60        DO_ICALL                                                     
   47    61        INIT_FCALL                                                   'array_slice'
         62        SEND_VAR                                                     !5
         63        SEND_VAL                                                     0
         64        SEND_VAL                                                     10
         65        DO_ICALL                                             $41     
         66        ASSIGN                                                       !5, $41
   50    67        ASSIGN                                                       !7, ''
   51    68      > FE_RESET_R                                           $44     !5, ->74
         69    > > FE_FETCH_R                                           ~45     $44, !8, ->74
         70    >   ASSIGN                                                       !4, ~45
   52    71        CONCAT                                               ~47     '+', !4
         72        ASSIGN_OP                                         8          !7, ~47
   51    73      > JMP                                                          ->69
         74    >   FE_FREE                                                      $44
   55    75        FRAMELESS_ICALL_2                trim                ~49     !7, '+'
         76      > RETURN                                                       ~49
   56    77*     > RETURN                                                       null

End of function generatekeywordsfromtext

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
172.4 ms | 2146 KiB | 18 Q