當前位置: 首頁>>代碼示例>>PHP>>正文


PHP metaphone函數代碼示例

本文整理匯總了PHP中metaphone函數的典型用法代碼示例。如果您正苦於以下問題:PHP metaphone函數的具體用法?PHP metaphone怎麽用?PHP metaphone使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了metaphone函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: compare

 function compare($debug = false)
 {
     $first = $this->str1;
     $second = $this->str2;
     $this->levenshtein = levenshtein($first, $second);
     $this->similarity['value'] = $sim = similar_text($first, $second, $perc);
     $this->similarity['percentage'] = $perc;
     if ($debug) {
         echo "{$first} | {$second}<br>";
         echo "leven: " . $this->levenshtein;
         echo '<br>similarity: ' . $sim . ', ' . $perc . '%<br><br>';
     }
     $soundex1 = soundex($first);
     $soundex2 = soundex($second);
     $this->soundex['levenshtein'] = levenshtein($soundex1, $soundex2);
     $this->soundex['similarity'] = $sim = similar_text($soundex1, $soundex2, $perc);
     $this->soundex['percentage'] = $perc;
     if ($debug) {
         echo "Soundex: " . $soundex1 . ", " . $soundex2 . "<BR>";
         echo 'levenshtein: ' . $this->soundex['levenshtein'] . '<br>';
         echo 'similarity: ' . $sim . ', ' . $perc . '%<br><br>';
     }
     $m1 = metaphone($first);
     $m2 = metaphone($second);
     $this->metaphone['levenshtein'] = levenshtein($m1, $m2);
     $this->metaphone['similarity'] = $sim = similar_text($m1, $m2, $perc);
     $this->metaphone['percentage'] = $perc;
     if ($debug) {
         echo "metaphone: " . $m1 . ", " . $m2 . "<br>";
         echo 'levenshtein: ' . $this->metaphone['levenshtein'] . '<br>';
         echo 'similarity: ' . $sim . ', ' . $perc . '%<br>';
         echo '<br>-------------------<br>';
     }
 }
開發者ID:superego546,項目名稱:SMSGyan,代碼行數:34,代碼來源:class.CompareString.php

示例2: similarWord

 /**
  *
  * @param string $word
  * @param array $words
  * @return array
  */
 public static function similarWord($word, array $words)
 {
     $similarity = config('pages.similar.similarity');
     $metaSimilarity = 0;
     $minLevenshtein = 1000;
     $metaMinLevenshtein = 1000;
     $result = [];
     $metaResult = [];
     foreach ($words as $n) {
         $minLevenshtein = min($minLevenshtein, levenshtein($n, $word));
     }
     foreach ($words as $n => $k) {
         if (levenshtein($k, $word) <= $minLevenshtein) {
             if (similar_text($k, $word) >= $similarity) {
                 $result[$n] = $k;
             }
         }
     }
     foreach ($result as $n) {
         $metaMinLevenshtein = min($metaMinLevenshtein, levenshtein(metaphone($n), metaphone($word)));
     }
     foreach ($result as $n) {
         if (levenshtein($n, $word) == $metaMinLevenshtein) {
             $metaSimilarity = max($metaSimilarity, similar_text(metaphone($n), metaphone($word)));
         }
     }
     foreach ($result as $n => $k) {
         if (levenshtein(metaphone($k), metaphone($word)) <= $metaMinLevenshtein) {
             if (similar_text(metaphone($k), metaphone($word)) >= $metaSimilarity) {
                 $metaResult[$n] = $k;
             }
         }
     }
     return $metaResult;
 }
開發者ID:BlueCatTAT,項目名稱:kodicms-laravel,代碼行數:41,代碼來源:Text.php

示例3: search_items

 function search_items()
 {
     $search_string = $this->input->post('keyword');
     $search_string = preg_replace('/[^a-zA-Z0-9_ %\\[\\]\\.\\(\\)%&-]/s', '', $search_string);
     $words = explode(" ", $search_string);
     $data = $this->browse_gallery_model->get_all_search_strings();
     $row = 0;
     $row_array = array();
     $ad_array = array();
     foreach ($data as $text) {
         $text_word = explode("~", $text['Title_Text']);
         $ad_id = $text['ad_id'];
         $count = 0;
         foreach ($text_word as $single) {
             foreach ($words as $keyword) {
                 if (soundex(strtoupper($keyword)) == soundex(strtoupper($single)) || metaphone(strtoupper($keyword)) == metaphone(strtoupper($single))) {
                     $count = $count + 1;
                 }
             }
         }
         if (intval($count) > 0) {
             array_push($row_array, $ad_id);
         }
     }
     if (!empty($row_array)) {
         $data['ads'] = $this->browse_gallery_model->get_gallery_ads_by_adid($row_array);
         $data['top'] = $this->browse_gallery_model->get_top_categories();
         $this->load->view('search_items_view', $data);
     } else {
         $data['ads'] = NULL;
         $data['top'] = $this->browse_gallery_model->get_top_categories();
         $this->load->view('search_items_view', $data);
     }
 }
開發者ID:maheshrathnayaka,項目名稱:2014_Sep_13,代碼行數:34,代碼來源:browse_gallery.php

示例4: testStringPreparation

 public function testStringPreparation()
 {
     $string = new String();
     $testString = "This is my-book title. BY Jesse.";
     $actual = $string->prepare($testString);
     $expected = [metaphone('this'), metaphone('book'), metaphone('title'), metaphone('jesse')];
     $this->assertEquals($actual, $expected);
 }
開發者ID:jesseobrien,項目名稱:reach,代碼行數:8,代碼來源:StringTest.php

示例5: compareMetaphone

function compareMetaphone($v1, $v2)
{
    $v1 = metaphone($v1);
    $v2 = metaphone($v2);
    similar_text($v1, $v2, $p);
    // return similarity percentage
    return $p;
}
開發者ID:bffmm1,項目名稱:gmailcommunity,代碼行數:8,代碼來源:compare.php

示例6: strmp

function strmp($str)
{
    $arr = explode(' ', $str);
    foreach ($arr as $ind => $word) {
        $word = trim($word);
        $arr[$ind] = metaphone($word);
    }
    $str = implode(' ', $arr);
    return $str;
}
開發者ID:jftsang,項目名稱:flashcards,代碼行數:10,代碼來源:strmp.php

示例7: testMultipleFind

 public function testMultipleFind()
 {
     $redis = m::mock('Illuminate\\Redis\\Database');
     $redis->shouldReceive('sinter')->times(2)->andReturn([1], []);
     $string = m::mock('Reach\\String');
     $string->shouldReceive('prepare')->times(2)->andReturn([metaphone('the'), metaphone('story')], [metaphone('the'), metaphone('story')]);
     $string->shouldReceive('stripPunctuation')->times(2)->andReturn('books', 'authors');
     $reach = new Reach($redis, $string);
     $expected = ['books' => [1], 'authors' => []];
     $this->assertEquals($reach->findIn(['books', 'authors'], 'the story'), $expected);
 }
開發者ID:jesseobrien,項目名稱:reach,代碼行數:11,代碼來源:ReachTest.php

示例8: similar_phase

function similar_phase($a, $b)
{
    $a = metaphone($a);
    $b = metaphone($b);
    $na = strlen($a);
    $nb = strlen($b);
    $n = $nb;
    if ($na > $nb) {
        $n = $na;
    }
    return levenshtein($a, $b) * 100.0 / $n;
}
開發者ID:1upon0,項目名稱:ui,代碼行數:12,代碼來源:lib_func.php

示例9: prepare

 /**
  * Prepare a string to have it's pieces inserted into the search index
  *
  * @param string $term
  * @return array
  */
 public function prepare($string)
 {
     $string = strtolower($this->stripPunctuation($string));
     $string = str_replace("-", " ", $string);
     $terms = explode(" ", $string);
     $prepared = [];
     foreach ($terms as &$t) {
         if (!$this->isStopWord($t) and strlen($t) >= 3) {
             $prepared[] = metaphone($t);
         }
     }
     return $prepared;
 }
開發者ID:jesseobrien,項目名稱:reach,代碼行數:19,代碼來源:String.php

示例10: formatRecord

function formatRecord($person, $merge_with = array())
{
    $base_person = array('pidm' => '', 'wpid' => '', 'psu_id' => '', 'username' => '', 'email' => '', 'msc' => '', 'name_first' => '', 'name_first_formatted' => '', 'name_first_metaphone' => '', 'name_last' => '', 'name_last_formatted' => '', 'name_last_metaphone' => '', 'name_middle_formatted' => '', 'name_full' => '', 'phone_of' => '', 'phone_vm' => '', 'emp' => '0', 'stu' => '0', 'stu_account' => '0', 'dept' => '', 'title' => '', 'major' => '', 'has_idcard' => '0');
    $person['office_phone'] = PSU::stripPunct($person['office_phone']);
    $person['phone_number'] = PSU::stripPunct($person['phone_number']);
    if ($merge_with) {
        $merge_with = PSU::params($merge_with, $base_person);
        $person = PSU::params($person, $merge_with);
    } else {
        $person = PSU::params($person, $base_person);
    }
    //end else
    $final = array('pidm' => $person['pidm'], 'wpid' => $person['wp_id'], 'psu_id' => $person['psu_id'], 'username' => !strpos($person['username'], '@') ? trim($person['username']) : substr($person['username'], 0, strpos($person['username'], '@')), 'email' => !strpos($person['email'], '@') ? trim($person['email']) : substr($person['email'], 0, strpos($person['email'], '@')), 'msc' => $person['msc'] ? $person['msc'] : '', 'name_first' => PSU::stripPunct($person['first_name']), 'name_first_formatted' => $person['first_name'], 'name_first_metaphone' => metaphone(PSU::stripPunct($person['first_name'])), 'name_last' => PSU::stripPunct($person['last_name']), 'name_last_formatted' => $person['last_name'], 'name_last_metaphone' => metaphone(PSU::stripPunct($person['last_name'])), 'name_middle_formatted' => $person['middle_name'], 'name_full' => trim(preg_replace('/\\s\\s+/', ' ', $person['first_name'] . ' ' . substr($person['middle_name'], 0, 1) . ' ' . $person['last_name'] . ' ' . $person['spbpers_name_suffix'])), 'phone_of' => $person['office_phone'] ? '(603) ' . substr($person['office_phone'], 0, 3) . '-' . substr($person['office_phone'], 3) : FALSE, 'phone_vm' => $person['phone_number'] ? '(603) ' . substr($person['phone_number'], 0, 3) . '-' . substr($person['phone_number'], 3) : FALSE, 'emp' => $person['emp'] ? 1 : 0, 'stu' => $person['stu'] ? 1 : 0, 'stu_account' => $person['stu_account'] ? 1 : 0, 'dept' => $person['department'] ?: '', 'title' => $person['title'] ?: '', 'major' => $person['major'] ?: '', 'has_idcard' => $person['has_idcard']);
    return $final;
}
開發者ID:AholibamaSI,項目名稱:plymouth-webapp,代碼行數:15,代碼來源:phonebook.lib.php

示例11: customize

function customize()
{
    print metaphone("That's just wack");
    $fields = array();
    $fields["heading_1"] = COMP_NAME;
    $fields["heading_2"] = date("d/m/Y");
    $fields["heading_3"] = "Balance Sheet";
    $fields["heading_4"] = "Prepared by: " . USER_NAME;
    foreach ($fields as $var_name => $value) {
        ${$var_name} = $value;
    }
    db_conn("cubit");
    $OUTPUT = "<table border='0' cellpadding='0' cellspacing='0' width='100%'>\n\t\t<tr>\n\t\t\t<td align='left'><h3>{$heading_1}</h3></td>\n\t\t\t<td align='right'><h3>{$heading_2}</h3></td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td align='left'><h3>{$heading_3}</h3></td>\n\t\t\t<td align='right'><h3>{$heading_4}</h3></td>\n\t\t</tr>\n\t</table>\n\t<table border=0 cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "'>\n\t\t<tr>\n\t\t\t<th>";
    return $OUTPUT;
}
開發者ID:andrecoetzee,項目名稱:accounting-123.com,代碼行數:15,代碼來源:bal-sheet.new.php

示例12: decode

 /**
  * Get web wervice polyline parameter being decoded
  * @param $rsp - string 
  * @param string $param - response key
  * @return string - JSON
  */
 protected function decode($rsp, $param = 'routes.overview_polyline.points')
 {
     $needle = metaphone($param);
     // get response
     $obj = json_decode($rsp, true);
     // flatten array into single level array using 'dot' notation
     $obj_dot = array_dot($obj);
     // create empty response
     $response = [];
     // iterate
     foreach ($obj_dot as $key => $val) {
         // Calculate the metaphone key and compare with needle
         $val = strcmp(metaphone($key, strlen($needle)), $needle) === 0 ? PolyUtil::decode($val) : $val;
         array_set($response, $key, $val);
     }
     return json_encode($response, JSON_PRETTY_PRINT);
 }
開發者ID:drickferreira,項目名稱:rastreador,代碼行數:23,代碼來源:Directions.php

示例13: findPhonetically

 public function findPhonetically($productName)
 {
     $productNameMeta = metaphone($productName);
     $map = [];
     $max = SIMILAR_MIN_THRESHOLD;
     $productId = 0;
     $products = Product::scope()->with('default_tax_rate')->get();
     foreach ($products as $product) {
         if (!$product->product_key) {
             continue;
         }
         $map[$product->id] = $product;
         $similar = similar_text($productNameMeta, metaphone($product->product_key), $percent);
         if ($percent > $max) {
             $productId = $product->id;
             $max = $percent;
         }
     }
     return $productId && isset($map[$productId]) ? $map[$productId] : null;
 }
開發者ID:rafaelsisweb,項目名稱:invoice-ninja,代碼行數:20,代碼來源:ProductRepository.php

示例14: getMetaphoneM

function getMetaphoneM($first, $second, $result)
{
    $arFirst = explode(" ", $first);
    $arSecond = explode(" ", $second);
    $m1 = $m2 = "";
    foreach ($arFirst as $val) {
        $m1 .= metaphone($val);
    }
    foreach ($arSecond as $val2) {
        $m2 .= metaphone($val2);
    }
    $metaphone['levenshtein'] = levenshtein($m1, $m2);
    $metaphone['similarity'] = similar_text($m1, $m2, $perc);
    $metaphone['percentage'] = $perc;
    if ($result['levenshtein'] > $metaphone['levenshtein'] && $result['percentage'] <= $metaphone['percentage']) {
        $result["levenshtein"] = $metaphone['levenshtein'];
        $result["percentage"] = $metaphone['percentage'];
        $result["match"] = $second;
    }
    return $result;
}
開發者ID:superego546,項目名稱:SMSGyan,代碼行數:21,代碼來源:mobile_UAE.php

示例15: pleac_Soundex_Matching

function pleac_Soundex_Matching()
{
    #-----------------------------
    $code = soundex($string);
    #-----------------------------
    $phoned_words = metaphone("Schwern");
    #-----------------------------
    // substitution function for getpwent():
    // returns an array of user entries,
    // each entry contains the username and the full name
    function getpwent()
    {
        $pwents = array();
        $handle = fopen("passwd", "r");
        while (!feof($handle)) {
            $line = fgets($handle);
            if (preg_match("/^#/", $line)) {
                continue;
            }
            $cols = explode(":", $line);
            $pwents[$cols[0]] = $cols[4];
        }
        return $pwents;
    }
    print "Lookup user: ";
    $user = rtrim(fgets(STDIN));
    if (empty($user)) {
        exit;
    }
    $name_code = soundex($user);
    $pwents = getpwent();
    foreach ($pwents as $username => $fullname) {
        preg_match("/(\\w+)[^,]*\\b(\\w+)/", $fullname, $matches);
        list(, $firstname, $lastname) = $matches;
        if ($name_code == soundex($username) || $name_code == soundex($lastname) || $name_code == soundex($firstname)) {
            printf("%s: %s %s\n", $username, $firstname, $lastname);
        }
    }
    #-----------------------------
}
開發者ID:Halfnhav4,項目名稱:pfff,代碼行數:40,代碼來源:Soundex_Matching.php


注:本文中的metaphone函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。