<?php
/**********************************************************************************
******
****** class name : lovematch
****** language : php
****** author : Martin Lacher
****** contact : m|a|r|t|i|n dot l|a|c|h|e|r at w|e|b dot d|e
****** version : 1.0
****** date : 03/22/2004
****** licence : gnu-gpl
******
****** Free for private use, for commercial use contact the author.
******
**********************************************************************************/
/**********************************************************************************
******
****** How much does your name fit to your loved one's?
******
**********************************************************************************/
/**********************************************************************************
******
****** List of public funtions:
****** - int match(string name1, string name2)
****** - string message(int match, string name1, string name2)
******
**********************************************************************************/
class lovematch {
/**********************************************************************************
****** the love ;-) algorithm
**********************************************************************************/
function match($n1, $n2) {
$s1 = 0;
$s2 = 0;
for($i=0; $i<strlen($n1); $i++)
$s1 += ord($n1[$i])/($i+1);
for($i=0; $i<strlen($n2); $i++)
$s2 += ord($n2[$i])/($i+1);
$m = ($s1+$s2)/(($s1-$s2)+1);
$m = substr($m*1000, 2,2);
return $m;
}
/**********************************************************************************
****** these are the messages message() will return
****** $m25 are messages for lovematches below 25%, $m50 below 50% and so on
****** you can just add some messages or replace mine ;-)
**********************************************************************************/
var $m25 = array("n1 shouldn't even try",
"Another Message here");
var $m50 = array("n1 loves n2, but n2 doens't know what to do.",
"Another Message here");
var $m75 = array("n2 and n1 like each other very much. Keep it going!");
var $m100 = array("Perfect match. Get married!",
"Another Message here");
/**********************************************************************************
****** the function that will return a message according to your
****** love- match-value
**********************************************************************************/
function message($m, $n1, $n2) {
mt_srand((double)microtime()*1000000);
if($m<25)
$msg = $this->m25[mt_rand(0,count($this->m25)-1)];
elseif($m<50)
$msg = $this->m50[mt_rand(0,count($this->m50)-1)];
elseif($m<75)
$msg = $this->m75[mt_rand(0,count($this->m75)-1)];
elseif($m<100)
$msg = $this->m100[mt_rand(0,count($this->m100)-1)];
$msg = str_replace(array("n1","n2"), array($n1, $n2), $msg);
return $msg;
}
}
?>