⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 class.doublemetaphone.php

📁 Typo3, 开源里边最强大的
💻 PHP
字号:
<?php// VERSION DoubleMetaphone Class 1.01//// DESCRIPTION////   This class implements a "sounds like" algorithm developed//   by Lawrence Philips which he published in the June, 2000 issue//   of C/C++ Users Journal.  Double Metaphone is an improved//   version of Philips' original Metaphone algorithm.//// COPYRIGHT////   Copyright 2001, Stephen Woodbridge <woodbri@swoodbridge.com>//   All rights reserved.////   http://swoodbridge.com/DoubleMetaPhone/////   This PHP translation is based heavily on the C implementation//   by Maurice Aubrey <maurice@hevanet.com>, which in turn//   is based heavily on the C++ implementation by//   Lawrence Philips and incorporates several bug fixes courtesy//   of Kevin Atkinson <kevina@users.sourceforge.net>.////   This module is free software; you may redistribute it and/or//   modify it under the same terms as Perl itself.//// CONTRIBUTIONS////   17-May-2002 Geoff Caplan  http://www.advantae.com//     Bug fix: added code to return class object which I forgot to do//     Created a functional callable version instead of the class version//     which is faster if you are calling this a lot.//// ------------------------------------------------------------------// TYPO3: Had to change name to "user_DoubleMetaPhone" from just "DoubleMetaPhone" because TYPO3 requires a user class to be prefixed so:// TYPO3: If you want to use this metaphone method instead of the default in the class.indexer.php you simply configure TYPO3 so by setting the line below in your localconf.php file:// TYPO3:			$TYPO3_CONF_VARS['EXTCONF']['indexed_search']['metaphone'] = 'EXT:indexed_search/class.doublemetaphone.php:&user_DoubleMetaPhone';// TYPO3: Of course you can write your own metaphone hook methods by taking this class and configuration as example.class user_DoubleMetaPhone{//  properties   var $original  = "";   var $primary   = "";   var $secondary = "";   var $length    =  0;   var $last      =  0;   var $current   =  0;//  methods		// TYPO3 specific API to this class. BEGIN	function metaphone($string,$sys_language_uid=0)	{		$res = $this->DoubleMetaPhone($string);		#debug(array($string,$res['primary']));		return $res['primary'];	}		// TYPO3 specific API to this class. END  // Public method  function DoubleMetaPhone($string) {   $this->primary   = "";   $this->secondary = "";   $this->current   =  0;    $this->current  = 0;    $this->length   = strlen($string);    $this->last     = $this->length - 1;    $this->original = $string . "     ";    $this->original = strtoupper($this->original);    // skip this at beginning of word    if ($this->StringAt($this->original, 0, 2,                        array('GN', 'KN', 'PN', 'WR', 'PS')))      $this->current++;    // Initial 'X' is pronounced 'Z' e.g. 'Xavier'    if (substr($this->original, 0, 1) == 'X') {      $this->primary   .= "S";   // 'Z' maps to 'S'      $this->secondary .= "S";      $this->current++;    }    // main loop    while (strlen($this->primary) < 4 || strlen($this->secondary < 4)) {      if ($this->current >= $this->length)        break;      switch (substr($this->original, $this->current, 1)) {        case 'A':        case 'E':        case 'I':        case 'O':        case 'U':        case 'Y':          if ($this->current == 0) {            // all init vowels now map to 'A'            $this->primary   .= 'A';            $this->secondary .= 'A';          }          $this->current += 1;          break;        case 'B':          // '-mb', e.g. "dumb", already skipped over ...          $this->primary   .= 'P';          $this->secondary .= 'P';          if (substr($this->original, $this->current + 1, 1) == 'B')            $this->current += 2;          else            $this->current += 1;          break;        case '

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -