Friday, September 25, 2009

Numerology


<?php
if(($q = (($_GET['q']) ? ($_GET['q']) : ($_POST['q']))) != '') {
$c = (($_GET['c']) ? ($_GET['c']) : ($_POST['c']));
if($c % 2) $q = strtoupper($q); elseif($c == 2) $q = strtolower($q);
if($c == 3) $x = -64;
$str = str_split($q);
for($i = 0, $n = 0; $i < count($str); $i++) {
$n += ord($str[$i]) + $x;
//echo $str[$i].' - '.$n.'<br/>';
}
header("Location: http://www.wolframalpha.com/input/?i=".urlencode($n));
}
?>

<html><body>
<form method="post" action="<?php echo $PHP_SELF; ?>">
String:<br/><input type="text" name="q" value="" />
<select name="c">
<option value="0">case sensitive</option>
<option value="1">upper case</option>
<option value="2">lower case</option>
<option selected value="3">alphabetical</option
</select><input type="submit" />
</form>
</body></html>