Last active
June 18, 2016 21:03
-
-
Save dmitriy-sqrt/a244cd09bdb636abb6d7e78695e46176 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$birth_date = htmlentities($_GET['birth_date']); | |
if (preg_match("/([0-9]{2})\.([0-9]{2})\.([0-9]{4})/", $birth_date) === 0) | |
$error = 'Неправильный формат даты.'; | |
#$birth_date = '21.04.1991'; | |
$date = []; | |
list($date['day'], $date['month'], $date['year']) = explode('.', $birth_date); | |
$date['date'] = $date['day'].$date['month']; | |
function magic($number) | |
{ | |
$number = intval($number); | |
$rows = []; | |
while($number > 9) | |
{ | |
if ($number > 100) | |
{ | |
$p1 = floor($number/100); | |
$p2 = floor($number%100); | |
} | |
else | |
{ | |
$p1 = floor($number/10); | |
$p2 = floor($number%10); | |
} | |
$number = $p1+$p2; | |
$rows[] = "$p1 + $p2"; | |
$rows[] = strval($number); | |
} | |
return $rows; | |
} | |
$date_rows = magic($date['date']); | |
$year_rows = magic($date['year']); | |
$rows_count = max(count($year_rows), count($date_rows)); | |
$step = end($date_rows) + end($year_rows); | |
$mission = array_sum(str_split($step)); | |
?> | |
<html> | |
<head> | |
<meta charset=utf-8> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous"> | |
<style type="text/css"> | |
tr td{ | |
text-align: center; | |
} | |
tr td:first-of-type:before{ | |
content: "-"; | |
} | |
tr:nth-child(4n+1) td:first-of-type:before,tr:nth-child(4n+2) td:first-of-type:before{ | |
content: "+"; | |
} | |
</style> | |
</head> | |
<body> | |
<form class="form-inline"> | |
<div class="form-group"> | |
<label for="exampleInputName2">Дата рождения</label> | |
<input type="text" class="form-control" name='birth_date' placeholder="27.12.1976" value="<?php echo $birth_date; ?>"> | |
</div> | |
<button type="submit" class="btn btn-default">Рассчитать</button> | |
</form> | |
<?php if (isset($error)) { ?> | |
<?php echo $error; ?> | |
<?php } else { ?> | |
<table class="table table-bordered table-striped"> | |
<tr> | |
<td></td> | |
<td><?php echo $date['day'].'.'.$date['month'];?></td> | |
<td><?php echo $date['year'];?></td> | |
</tr> | |
<?php | |
for($i=0; $i<$rows_count; $i++) | |
{ | |
$v1 = (isset($date_rows[$i])) ? $date_rows[$i] : end($date_rows); | |
$v2 = (isset($year_rows[$i])) ? $year_rows[$i] : end($year_rows); | |
echo " | |
<tr> | |
<td></td> | |
<td>$v1</td> | |
<td>$v2</td> | |
</tr>"; | |
} | |
?> | |
<tr> | |
<td></td> | |
<td colspan="2"><?php echo $v1+$v2; ?></td> | |
</tr> | |
</table> | |
<div class="well"> | |
Дата: | |
<i><?php echo $birth_date; ?></i> | |
Миссия: | |
<b><?php echo $mission; ?></b> | |
Ступень: | |
<b><?php echo $step; ?></b> | |
</div> | |
<?php } ?> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment