Home > Backend Development > PHP Tutorial > Remove duplicate words from the string and generate an index string_PHP tutorial

Remove duplicate words from the string and generate an index string_PHP tutorial

WBOY
Release: 2016-07-20 11:07:04
Original
758 people have browsed it

Remove repeated words in the string and generate an index string
//--------------------------------- --------------------
function GetIndexText($okstr,$ilen=-1)
{
if($okstr=="" ) return "";
$ws = explode(" ",$okstr);
$okstr = "";
$wks = "";
foreach($ws as $w)
{
$w = trim($w);
//Exclude characters less than 2
if(strlen($w)<2) continue;
//Exclude numbers or dates
If(!ereg("[^0-9:-]",$w)) continue;
if(strlen($w)==2&&ord($w[0])>0x80) continue ;
if(isset($wks[$w])) $wks[$w]++;
else $wks[$w] = 1;
}
if(is_array($ wks))
{
arsort($wks);
if($ilen==-1)
{ foreach($wks as $w=>$v) $okstr .= $ w." "; }
else
{
foreach($wks as $w=>$v){
if((strlen($okstr)+strlen($w)+1 ; >




http://www.bkjia.com/PHPjc/444979.html

www.bkjia.com
true

http: //www.bkjia.com/PHPjc/444979.htmlTechArticleRemove repeated words in the string and generate an index string //---------- ---------------------------------------- function GetIndexText($okstr,$ilen=- 1) { if($okstr==) return ; $ws = explod...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template