怎么做土耳其语字符和详细的搜索和匹配?

时间:2013-12-27 11:02:35

标签: php replace

我想为土耳其语做一篇文章微调器。但是当我输入一个单词以ı,ö,ü,ş,ç开头或完成这个单词时它什么都不做。例如:

  

şarap|şurup

键入şarap时不匹配,但英文字符没有问题。我也在尝试对数据库进行详细搜索(单词宝藏)。

我的代码:

*/**
* spin an article using a treasure database : treasure.dat
*/*

    class wp_auto_spin_spin{

*/*
* function wp_auto_spin_spin : spins an article by replacing synonyms from database     treasure.dat
* @article: the article to be spinned
* return : the spinned article spinned or false if error.
*/* 

    function spin($article) {


*//prepare the article : repalce images with codes* 

    preg_match_all("/<[^<>]+>/is",$article,$matches,PREG_PATTERN_ORDER);

    $htmlfounds=$matches[0];



**//extract all shortcodes**

    $pattern="\[.*?\]";

    preg_match_all("/".$pattern."/s",$article,$matches2,PREG_PATTERN_ORDER);

    $shortcodes=$matches2[0];



*// merge shortcodes to html which should be replaced*

    $htmlfounds=array_merge($htmlfounds,$shortcodes);

    foreach($htmlfounds as $htmlfound){

    $article=str_replace($htmlfound,'('.md5($htmlfound).')',$article);

            }

*//open the treasures db*

    $file=file(dirname(__FILE__)  .'/treasure.dat');
    $founds=array();


*//checking all words for existance*

    foreach($file as $line){


*//each synonym word*

    $synonyms=explode('|',$line);

    foreach($synonyms as $word){

    if(trim($word) != ''){

    *//check word existance* 

    *//echo '<br>'.$word;*



    $word=str_replace('/','\/',$word);          

    if(preg_match('/\b'. $word .'\b/i', $article)) {

*//echo '<br>has the word  '.$word;
//replace the word with it's hash and add it to the array for restoring to prevent duplicate*

    $founds[md5($word)]=str_replace(array("\n", "\r"), '',$line);

$article=preg_replace('/\b'.$word.'\b/i',md5($word),$article);


            }
            }
        }   

    }
*//foreach line of the synonyms file*


*//restore html tags*

    foreach($htmlfounds as $htmlfound){

    $article=str_replace('('.md5($htmlfound).')',$htmlfound,$article);

        }

*//replace hashes with synonyms*

    if(count($founds) !=0){

    foreach ($founds as $key=>$val){

    $article=str_replace($key,'{'.$val.'}',$article);
        }
     }
     return $article;
         ;
        }
        }

0 个答案:

没有答案