3v4l.org

run code in 300+ 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 = 30, Position 2 = 49
Branch analysis from position: 30
2 jumps found. (Code = 78) Position 1 = 31, Position 2 = 49
Branch analysis from position: 31
2 jumps found. (Code = 47) Position 1 = 34, Position 2 = 42
Branch analysis from position: 34
2 jumps found. (Code = 47) Position 1 = 43, Position 2 = 46
Branch analysis from position: 43
2 jumps found. (Code = 43) Position 1 = 47, Position 2 = 48
Branch analysis from position: 47
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
Branch analysis from position: 48
Branch analysis from position: 46
Branch analysis from position: 42
Branch analysis from position: 49
2 jumps found. (Code = 43) Position 1 = 53, Position 2 = 69
Branch analysis from position: 53
2 jumps found. (Code = 77) Position 1 = 54, Position 2 = 68
Branch analysis from position: 54
2 jumps found. (Code = 78) Position 1 = 55, Position 2 = 68
Branch analysis from position: 55
2 jumps found. (Code = 43) Position 1 = 62, Position 2 = 65
Branch analysis from position: 62
1 jumps found. (Code = 42) Position 1 = 67
Branch analysis from position: 67
1 jumps found. (Code = 42) Position 1 = 54
Branch analysis from position: 54
Branch analysis from position: 65
1 jumps found. (Code = 42) Position 1 = 54
Branch analysis from position: 54
Branch analysis from position: 68
2 jumps found. (Code = 77) Position 1 = 80, Position 2 = 85
Branch analysis from position: 80
2 jumps found. (Code = 78) Position 1 = 81, Position 2 = 85
Branch analysis from position: 81
1 jumps found. (Code = 42) Position 1 = 80
Branch analysis from position: 80
Branch analysis from position: 85
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 85
Branch analysis from position: 68
Branch analysis from position: 69
Branch analysis from position: 49
filename:       /in/jdhDi
function name:  generateKeywordsFromText
number of ops:  92
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        INIT_FCALL                                               'preg_replace'
          3        SEND_VAL                                                 '%2F%5Cs%7B2%2C%7D%2Fui'
          4        SEND_VAL                                                 ''
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $10     
          7        ASSIGN                                                   !0, $10
   12     8        INIT_FCALL                                               'trim'
          9        SEND_VAR                                                 !0
         10        DO_ICALL                                         $12     
         11        ASSIGN                                                   !0, $12
   13    12        INIT_FCALL                                               'preg_replace'
         13        SEND_VAL                                                 '%2F%5B%5E%5Cp%7BL%7D0-9+.-%5D%2B%2Fu'
         14        SEND_VAL                                                 ''
         15        SEND_VAR                                                 !0
         16        DO_ICALL                                         $14     
         17        ASSIGN                                                   !0, $14
   14    18        INIT_FCALL                                               'strtolower'
         19        SEND_VAR                                                 !0
         20        DO_ICALL                                         $16     
         21        ASSIGN                                                   !0, $16
   17    22        INIT_FCALL                                               'preg_match_all'
         23        SEND_VAL                                                 '%2F%5Cw%2B%2Fiu'
         24        SEND_VAR                                                 !0
         25        SEND_REF                                                 !2
         26        DO_ICALL                                                 
   18    27        FETCH_DIM_R                                      ~19     !2, 0
         28        ASSIGN                                                   !2, ~19
   21    29      > FE_RESET_R                                       $21     !2, ->49
         30    > > FE_FETCH_R                                       ~22     $21, !3, ->49
         31    >   ASSIGN                                                   !4, ~22
   23    32        IS_EQUAL                                         ~24     !3, ''
         33      > JMPNZ_EX                                         ~24     ~24, ->42
         34    >   INIT_FCALL                                               'in_array'
         35        INIT_FCALL                                               'strtolower'
         36        SEND_VAR                                                 !3
         37        DO_ICALL                                         $25     
         38        SEND_VAR                                                 $25
         39        SEND_VAR                                                 !1
         40        DO_ICALL                                         $26     
         41        BOOL                                             ~24     $26
         42    > > JMPNZ_EX                                         ~24     ~24, ->46
         43    >   STRLEN                                           ~27     !3
         44        IS_SMALLER_OR_EQUAL                              ~28     ~27, 3
         45        BOOL                                             ~24     ~28
         46    > > JMPZ                                                     ~24, ->48
   24    47    >   UNSET_DIM                                                !2, !4
   21    48    > > JMP                                                      ->30
         49    >   FE_FREE                                                  $21
   29    50        ASSIGN                                                   !5, <array>
   32    51        TYPE_CHECK                                  128          !2
         52      > JMPZ                                                     ~30, ->69
   33    53    > > FE_RESET_R                                       $31     !2, ->68
         54    > > FE_FETCH_R                                       ~32     $31, !6, ->68
         55    >   ASSIGN                                                   !4, ~32
   34    56        INIT_FCALL                                               'strtolower'
         57        SEND_VAR                                                 !6
         58        DO_ICALL                                         $34     
         59        ASSIGN                                                   !6, $34
   35    60        ISSET_ISEMPTY_DIM_OBJ                         0          !5, !6
         61      > JMPZ                                                     ~36, ->65
   36    62    >   FETCH_DIM_RW                                     $37     !5, !6
         63        PRE_INC                                                  $37
   35    64      > JMP                                                      ->67
   38    65    >   ASSIGN_DIM                                               !5, !6
         66        OP_DATA                                                  1
   33    67    > > JMP                                                      ->54
         68    >   FE_FREE                                                  $31
   44    69    >   INIT_FCALL                                               'arsort'
         70        SEND_REF                                                 !5
         71        DO_ICALL                                                 
   47    72        INIT_FCALL                                               'array_slice'
         73        SEND_VAR                                                 !5
         74        SEND_VAL                                                 0
         75        SEND_VAL                                                 10
         76        DO_ICALL                                         $41     
         77        ASSIGN                                                   !5, $41
   50    78        ASSIGN                                                   !7, ''
   51    79      > FE_RESET_R                                       $44     !5, ->85
         80    > > FE_FETCH_R                                       ~45     $44, !8, ->85
         81    >   ASSIGN                                                   !4, ~45
   52    82        CONCAT                                           ~47     '+', !4
         83        ASSIGN_OP                                     8          !7, ~47
   51    84      > JMP                                                      ->80
         85    >   FE_FREE                                                  $44
   55    86        INIT_FCALL                                               'trim'
         87        SEND_VAR                                                 !7
         88        SEND_VAL                                                 '+'
         89        DO_ICALL                                         $49     
         90      > RETURN                                                   $49
   56    91*     > RETURN                                                   null

End of function generatekeywordsfromtext

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
149.85 ms | 1020 KiB | 21 Q