bir dize Sembolleri aramak

0 Cevap php

Ben bazı kod yazma ve bir dize semboller bazı tür aramak gerekir ediyorum. Bunun için mb_strpos işlevi kullanmak ve alfabe sembolleri için çalışıyor ama ben bir dize mb_strpos in "aaaaa" (ya da herhangi başka bir unicode karakteri) için ararsanız ben Örneğin soru işareti, nokta ve benzeri gibi semboller için arama eğer değil Ben aramak eğer beklendiği gibi çalışır ama "???" öyle değil!

Bu benim kodudur:

function symbols_in_row($string, $limit=5) {
    //split string by characters and generate new array containing each character
    $symbol = preg_split('//u', $string, -1, PREG_SPLIT_NO_EMPTY);
    //remove duplicate symbols from array
    $unique = array_unique($symbol);
    //generate combination of symbols and search for them in string
    for($x=0; $x<=count($unique); $x++) {
        //generate combination of symbols
        for($c=1; $c<=$limit; $c++) {
            $combination .= $unique[$x];
        }
        //search for this combination of symbols in given string
        $pos = mb_strpos($string, $combination);
        if ($pos !== false) return false;
    }
    return true;
}

Her zaman ikinci durumda true döndürür!

Herkes yardım edebilir misiniz?

0 Cevap