This article mainly introduces the php method for automatically obtaining keywords. the custom function tiqukeyword is used to automatically obtain keywords, which has some reference value, for more information about how to automatically obtain keywords in php, see the example in this article. Share it with you for your reference.
The specific implementation method is as follows:
The code is as follows:
$ Mincipin = 5; // minimum word frequency
$ Minlen = 4; // minimum length of a keyword
Tiqukeyword ($ tiqustr, $ minlen, $ mincipin );
Function tiqukeyword ($ tiqustr, $ minlen, $ mincipin)
{$ Strlong = strlen ($ tiqustr );
$ Arr = array ();
$ K =-1;
For ($ I = 0; $ I <($ strlong-$ mincipin * $ minlen); $ I ++ ){
$ End = ceil ($ strlong-$ I)/$ mincipin + $ I );
For ($ j = $ minlen; $ j <$ end; $ j ++) {$ num = 0;
If ($ guanjianzi = substr ($ tiqustr, $ I, $ j ))! = False ){
$ Wz = $ I + $ j;
$ Num ++ ;}
Else {break ;}
While ($ wz <$ strlong) {if ($ wz = strpos ($ tiqustr, $ guanjianzi, $ wz ))! = False)
{$ Num ++;
$ Wz = $ wz + strlen ($ guanjianzi );}
Else break;
}
If ($ j = $ minlen ){
If ($ num >=$ mincipin) {$ maxnum = $ num; $ k ++; $ str = substr ($ tiqustr, $ I, $ j );
$ Arr [$ k] = array ($ I, $ j, $ str, $ num, 0 );
}
Else {break ;}
}
Else {
If ($ num> = $ maxnum ){
$ Maxnum = $ num;
$ Str = substr ($ tiqustr, $ I, $ j );
$ Arr [$ k] = array ($ I, $ j, $ str, $ num, 0 );
}
Else break;
}
}
}
Echo 'Preliminarily obtained array :';
Print_r ($ arr );
// Echo'
';
$ Arrlong = count ($ arr );
For ($ I = 0; $ I <$ arrlong; $ I ++ ){
$ Bjarr = $ arr [$ I];
$ Nowid = $ I;
If ($ bjarr [4] = 1) continue;
For ($ j = $ I + 1; $ j <$ arrlong; $ j ++ ){
If ($ arr [$ j] [4] = 1) continue;
$ Qujianks = $ bjarr [0];
$ Qujianjs = $ bjarr [1] + $ bjarr [0]-1;
$ A = $ arr [$ j] [0];
$ B = $ arr [$ j] [1] + $ arr [$ j] [0]-1;
If ($ bjarr [2] = $ arr [$ j] [2]) & ($ bjarr [3]> $ arr [$ j] [3]) $ arr [$ j] [4] = 1;
If ($ a <= $ qujianks & $ qujianks <= $ B & $ a <= $ qujianjs & $ qujianjs <= $ B)
{If ($ bjarr [3] <= $ arr [$ j] [3]) {
$ Arr [$ nowid] [4] = 1; $ nowid = $ j; $ bjarr = $ arr [$ j];
}
}
Elseif ($ qujianks <= $ a & $ a <= $ qujianjs & $ qujianks <= $ B & $ B <= $ qujianjs ){
$ Arr [$ j] [4] = 1;
}
}
}
Echo'
Relay the tagged array :';
Print_r ($ arr );
$ Jieguoarr = array ();
For ($ I = 0; $ I <$ arrlong; $ I ++)
{If ($ arr [$ I] [4] = 0) $ jieguoarr [] = $ arr [$ I];
}
Echo'
';
Echo 'final array :';
Print_r ($ jieguoarr );
}
I hope this article will help you with php programming.