function comparer($a, $b) { if ($a['accuracy'] > $b['accuracy']) { return -1; } if ($a['accuracy'] < $b['accuracy']) { return 1; } if ($a['accuracy'] == $b['accuracy']) { $aLev = levenshtein(Converter::ToLatin($a['value']), $GLOBALS['RhymeWord']); $bLev = levenshtein(Converter::ToLatin($b['value']), $GLOBALS['RhymeWord']); if ($aLev > $bLev) { return 1; } if ($aLev < $bLev) { return -1; } return 0; } }
function extractResult($filterType, $param) { $arr = array(); $servername = "localhost"; $username = "******"; $password = "******"; $dbname = "geoWords"; // Create connection $mysqli = new mysqli($servername, $username, $password, $dbname); /* check connection */ if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit; } if (!$mysqli->set_charset("utf8")) { printf("Error loading character set utf8: %s\n", $mysqli->error); exit; } $query = "select word_geo from words where word_eng " . $filterType . " ? "; if ($stmt = $mysqli->prepare($query)) { $param = Converter::ToLatin($param); $stmt->bind_param("s", $param); /* execute statement */ $stmt->execute(); // bind result variables $stmt->bind_result($word_value); $counter = 0; //fetch values while ($stmt->fetch()) { if ($counter++ > 999) { break; } array_push($arr, array('id' => $counter, 'value' => $word_value)); } /* close statement */ $stmt->close(); } $mysqli->close(); return $arr; }
function extractResult($filterType, $param) { $arr = array(); $query = "select word_geo from words where word_eng " . $filterType . " ? "; $mysqli = getMysqli(); $stmt = getStatementByQueryFromMysqli($query, $mysqli); $param = Converter::ToLatin($param); $stmt->bind_param("s", $param); /* execute statement */ $stmt->execute(); // bind result variables $stmt->bind_result($word_value); $counter = 0; //fetch values while ($stmt->fetch()) { if ($counter++ > 999) { break; } array_push($arr, array('id' => $counter, 'value' => $word_value)); } closeConnections($stmt, $mysqli); return $arr; }
<?php include 'common.php'; $param = $_GET['template']; $string = Converter::ToLatin($param); echo $param . '<br>'; echo "<br>"; $vowelsCount = vowelsCount($string); $rhymeLevel1Regex = '$'; $rhymeLevel2Regex = '$'; $rhymeLevel3Regex = '$'; $rhymeLevel4Regex = '$'; $rhymeLevel5Regex = '$'; $rhymeLevel6Regex = '$'; $splitedArray = splitBackPartByVowel($string); print_r($splitedArray); if ($vowelsCount > 0) { $ConsonantReplacer1 = ""; $ConsonantReplacer2 = ""; $ConsonantReplacer3 = ""; $ConsonantReplacer4 = ""; $ConsonantReplacer5 = ""; $ConsonantReplacer6 = "[^aeiou]*"; if ($splitedArray[5] != '') { $ConsonantReplacer1 = $splitedArray[5]; $ConsonantReplacer2 = ""; $ConsonantReplacer3 = ""; $ConsonantReplacer4 = ""; $ConsonantReplacer5 = ""; } $rhymeLevel1Regex = $splitedArray[4] . $ConsonantReplacer1 . $rhymeLevel1Regex;