public function process(LooPHP_EventLoop $event_loop, $timeout) { $read_resource_array = $this->_socket_array; $write_resource_array = NULL; $exception_resource_array = $this->_socket_array; $results = socket_select($read_resource_array, $write_resource_array, $exception_resource_array, is_null($timeout) ? NULL : floor($timeout), is_null($timeout) ? NULL : fmod($timeout, 1) * 1000000); if ($results === FALSE) { throw new Exception("stream_select failed"); } else { if ($results > 0) { foreach ($read_resource_array as $read_resource) { if ($this->_listen_socket === $read_resource) { $client_resource = @socket_accept($this->_listen_socket); $this->_socket_array[(int) $client_resource] = $client_resource; } else { //send http responce in 5 second (just to demo events) $event_loop->addEvent(function () use($read_resource) { $send_data = "HTTP/1.0 200 OK\n" . "Content-Type: text/html\n" . "Server: LooPHP" . "\r\n\r\n" . "<body>Hello World</body>"; socket_write($read_resource, $send_data); socket_close($read_resource); }, 5); unset($this->_socket_array[(int) $read_resource]); } } foreach ($exception_resource_array as $exception_resource) { print "Socket had exception\n"; unset($this->_socket_array[(int) $exception_resource]); } } } return TRUE; }
/** * verifica se o CPF é válido * * @param string $value cpf a ser validado * @return bool */ public function isValid($value) { //$value = preg_replace('/[^\d]+/i', '', $value); $this->setValue($value); if (!$this->skipFormat && preg_match($this->pattern, $value) == false) { $this->error(self::INVALID_FORMAT); return false; } $digits = preg_replace('/[^\\d]+/i', '', $value); $padroesFalsos = array(11111111111, 22222222222, 33333333333, 44444444444, 55555555555, 66666666666, 77777777777, 88888888888, 99999999999, 00); if (in_array($digits, $padroesFalsos)) { $this->error(self::INVALID_DIGITS); return false; } $firstSum = 0; $secondSum = 0; for ($i = 0; $i < 9; $i++) { $firstSum += $digits[$i] * (10 - $i); $secondSum += $digits[$i] * (11 - $i); } $firstDigit = 11 - fmod($firstSum, 11); if ($firstDigit >= 10) { $firstDigit = 0; } $secondSum = $secondSum + $firstDigit * 2; $secondDigit = 11 - fmod($secondSum, 11); if ($secondDigit >= 10) { $secondDigit = 0; } if (substr($digits, -2) != $firstDigit . $secondDigit) { $this->error(self::INVALID_DIGITS); return false; } return true; }
/** * Generate a valid Google Translate request token. * * @param string $a text to translate * * @return string */ private function TL($a) { $b = $this->generateB(); for ($d = [], $e = 0, $f = 0; $f < mb_strlen($a, 'UTF-8'); $f++) { $g = $this->charCodeAt($a, $f); if (128 > $g) { $d[$e++] = $g; } else { if (2048 > $g) { $d[$e++] = $g >> 6 | 192; } else { if (55296 == ($g & 64512) && $f + 1 < mb_strlen($a, 'UTF-8') && 56320 == ($this->charCodeAt($a, $f + 1) & 64512)) { $g = 65536 + (($g & 1023) << 10) + ($this->charCodeAt($a, ++$f) & 1023); $d[$e++] = $g >> 18 | 240; $d[$e++] = $g >> 12 & 63 | 128; } else { $d[$e++] = $g >> 12 | 224; $d[$e++] = $g >> 6 & 63 | 128; } } $d[$e++] = $g & 63 | 128; } } $a = $b; for ($e = 0; $e < count($d); $e++) { $a += $d[$e]; $a = $this->RL($a, '+-a^+6'); } $a = $this->RL($a, '+-3^+b+-f'); if (0 > $a) { $a = ($a & 2147483647) + 2147483648; } $a = fmod($a, pow(10, 6)); return $a . '.' . ($a ^ $b); }
private function ReadNumber($number) { $position_call = array("แสน", "หมื่น", "พัน", "ร้อย", "สิบ", ""); $number_call = array("", "หนึ่ง", "สอง", "สาม", "สี่", "ห้า", "หก", "เจ็ด", "แปด", "เก้า"); $number = $number + 0; $ret = ""; if ($number == 0) { return $ret; } if ($number > 1000000) { $ret .= $this->ReadNumber(intval($number / 1000000)) . "ล้าน"; $number = intval(fmod($number, 1000000)); } $divider = 100000; $pos = 0; while ($number > 0) { $d = intval($number / $divider); $ret .= $divider == 10 && $d == 2 ? "ยี่" : ($divider == 10 && $d == 1 ? "" : ($divider == 1 && $d == 1 && $ret != "" ? "เอ็ด" : $number_call[$d])); $ret .= $d ? $position_call[$pos] : ""; $number = $number % $divider; $divider = $divider / 10; $pos++; } return $ret; }
/** * formatPrice */ static function formatPrice($value, $currency_code) { $prefix = ''; $postfix = ''; if ($currency_code == "EUR") { $prefix = "€"; } if ($currency_code == "GBP") { $prefix = "£"; } if ($value < 1) { $value = $value * 100; $prefix = ''; if ($currency_code == "EUR") { $postfix = 'c'; } else { $postfix = 'p'; } } if (fmod($value, 1) > 0) { $price = number_format($value, 2); } else { $price = (int) $value; } return $prefix . $price . $postfix; }
function int_to_words($x) { global $nwords; if (!is_numeric($x)) { $w = '#'; } else { if (fmod($x, 1) != 0) { $w = '#'; } else { if ($x < 0) { $w = 'minus '; $x = -$x; } else { $w = ''; } if ($x < 21) { $w .= $nwords[$x]; } else { if ($x < 100) { $w .= $nwords[10 * floor($x / 10)]; $r = fmod($x, 10); if ($r > 0) { $w .= '-' . $nwords[$r]; } } else { if ($x < 1000) { $w .= $nwords[floor($x / 100)] . ' hundred'; $r = fmod($x, 100); if ($r > 0) { $w .= ' and ' . int_to_words($r); } } else { if ($x < 1000000) { $w .= int_to_words(floor($x / 1000)) . ' thousand'; $r = fmod($x, 1000); if ($r > 0) { $w .= ' '; if ($r < 100) { $w .= 'and '; } $w .= int_to_words($r); } } else { $w .= int_to_words(floor($x / 1000000)) . ' million'; $r = fmod($x, 1000000); if ($r > 0) { $w .= ' '; if ($r < 100) { $word .= 'and '; } $w .= int_to_words($r); } } } } } } } return $w; }
function do_main() { $this->aBreadcrumbs[] = array('url' => $_SERVER['PHP_SELF'], 'name' => _kt('Deleted Documents')); $this->oPage->setBreadcrumbDetails(_kt('view')); $aDocuments =& Document::getList('status_id=' . DELETED); if (!empty($aDocuments)) { $items = count($aDocuments); if (fmod($items, 10) > 0) { $pages = floor($items / 10) + 1; } else { $pages = $items / 10; } for ($i = 1; $i <= $pages; $i++) { $aPages[] = $i; } if ($items < 10) { $limit = $items - 1; } else { $limit = 9; } for ($i = 0; $i <= $limit; $i++) { $aDocumentsList[] = $aDocuments[$i]; } } $oTemplating =& KTTemplating::getSingleton(); $oTemplate = $oTemplating->loadTemplate('ktcore/document/admin/deletedlist'); $oTemplate->setData(array('context' => $this, 'fullList' => $aDocuments, 'documents' => $aDocumentsList, 'pagelist' => $aPages, 'pagecount' => $pages, 'itemcount' => $items)); return $oTemplate; }
/** * verifica se o cnpj é válido * * @param string $value cnpj a ser validado * @return bool */ public function isValid($value) { $this->_setValue($value); if (!$this->_skipFormat && preg_match($this->_pattern, $value) == false) { $this->_error(self::INVALID_FORMAT); return false; } $digits = preg_replace('/[^\\d]+/i', '', $value); $firstSum = 0; $secondSum = 0; $firstSum += 5 * $digits[0] + 4 * $digits[1] + 3 * $digits[2] + 2 * $digits[3]; $firstSum += 9 * $digits[4] + 8 * $digits[5] + 7 * $digits[6] + 6 * $digits[7]; $firstSum += 5 * $digits[8] + 4 * $digits[9] + 3 * $digits[10] + 2 * $digits[11]; $firstDigit = 11 - fmod($firstSum, 11); if ($firstDigit >= 10) { $firstDigit = 0; } $secondSum += 6 * $digits[0] + 5 * $digits[1] + 4 * $digits[2] + 3 * $digits[3]; $secondSum += 2 * $digits[4] + 9 * $digits[5] + 8 * $digits[6] + 7 * $digits[7]; $secondSum += 6 * $digits[8] + 5 * $digits[9] + 4 * $digits[10] + 3 * $digits[11]; $secondSum += $firstDigit * 2; $secondDigit = 11 - fmod($secondSum, 11); if ($secondDigit >= 10) { $secondDigit = 0; } if (substr($digits, -2) != $firstDigit . $secondDigit) { $this->_error(self::INVALID_DIGITS); return false; } return true; }
public static function ex3() { header('Content-type: application/json'); if (is_numeric($_POST['x'])) { $x = $_POST['x']; $p = $_POST['p']; if (is_numeric($p)) { $e = pow(10, -$p); if ($x > -M_PI && $x < M_PI) { $aprox = self::LentzAlgorithm($x, $e); $tan = tan($x); echo json_encode(array('aprox' => $aprox, 'tan' => $tan, 'pi' => M_PI, 'e' => $e, 'x' => $x)); exit; } elseif ($x < -M_PI || $x > M_PI) { if ($x < 0) { (double) ($real_x = fmod($x, -M_PI / 2)); } else { (double) ($real_x = fmod($x, M_PI / 2)); } $aprox = -self::LentzAlgorithm($real_x, $e); $tan = tan($x); echo json_encode(array('aprox' => $aprox, 'tan' => $tan, 'pi' => M_PI, 'e' => $e, 'x' => $x)); exit; } else { //$aprox=self::LentzAlgorithm($x,$e); //$tan=tan($x); echo json_encode(array('aprox' => 0, 'tan' => 0, 'pi' => 0, 'e' => 0, 'x' => 0)); exit; } } //if } //if }
function checksum($str) { if (strlen($str) == 0) { return 0x1000; } /* the floating point hacks are due to PHP's bugs when handling integers */ $a = 5381.0; for ($i = 0; $i < strlen($str); $i++) { $a = fmod($a + $a * 32 + ord($str[$i]), 4294967296.0); } if ($a > 2147483647.0) { $a -= 4294967296.0; } $a = (int) $a; $b = 0.0; for ($i = 0; $i < strlen($str); $i++) { $b = fmod($b * 64 + $b * 65536 - $b + ord($str[$i]), 4294967296.0); } if ($b > 2147483647.0) { $b -= 4294967296.0; } $b = (int) $b; $a = $a >> 6 & 0x3ffffc0 | $a >> 2 & 0x3f; $c = $a >> 4 & 0x3ffc00 | $a & 0x3ff; $d = $c >> 4 & 0x3c000 | $c & 0x3fff; $c = (($d & 0x3c0) << 4 | $d & 0x3c) << 2; $a = $b & 0xf0f; $e = $b & 0xf0f0000; $b = ($d & 4294950912.0) << 4 | $d & 0x3c00; return $b << 10 | $c | $a | $e; }
function generate_calendar() { $table_array = array(); //first day number for this month $table_array['first'] = date("z", mktime(0, 0, 0, $this->current_month, 1, $this->current_year)); //last day number of this month $table_array['last'] = date("z", mktime(0, 0, 0, $this->current_month + 1, 1, $this->current_year)); //special case for december as the silly php doesnt! if ($this->current_month == 12) { $table_array['last'] = 365; } //number of days in this month $table_array['days_in_current_month'] = $table_array['last'] - $table_array['first']; //day of week number for the first of day of the month (sunday=0, sat=6) $table_array['first_day_number'] = date("w", mktime(0, 0, 0, $this->current_month, 1, $this->current_year)); //first date - overlap from previous months $table_array['first_date_on_calendar'] = date("j", mktime(0, 0, 0, $this->current_month, 1 - $table_array['first_day_number'], $this->current_year)); //last day of the month $table_array['last_day_of_month'] = $table_array['days_in_current_month']; //number of days in the month + offset $table_array['last'] = $table_array['days_in_current_month'] + $table_array['first_day_number']; //how many days do we need to add to the end $table_array['mod'] = fmod($table_array['last'], 7); //last day to show on calendar - next month $table_array['last_date_on_calendar'] = 1 + (6 - $table_array['mod']); //if its an exact match blank it if ($table_array['last_date_on_calendar'] == 7) { $table_array['last_date_on_calendar'] = 0; } //total number of days to show on the calendar $table_array['days_on_calendar'] = $table_array['days_in_current_month'] + $table_array['first_day_number'] + $table_array['last_date_on_calendar']; return $table_array; }
public function crc($u, $n = 36) { $u = strtolower($u); $id = sprintf("%u", crc32($u)); $m = base_convert(intval(fmod($id, $n)), 10, $n); return $m[0]; }
/** * From roman to decimal numeral system * * @param string $sRoman * @return integer 0 on failure. */ public static function toDecimal($sRoman) { if (!is_string($sRoman)) { return 0; } $iStrLen = strlen($sRoman); $iDoubleSymbol = $iDec = $iPos = 0; foreach (self::$asRomanTransTable as $iNum => $sSymbol) { $iLen = strlen($sSymbol); $iCount = 0; if ($iDoubleSymbol) { --$iDoubleSymbol; continue; } # Mind the fact that 1000 in the Roman numeral system may be represented by M or i. while (($sChunk = substr($sRoman, $iPos, $iLen)) == $sSymbol || $iNum < 10000.0 && $sChunk == strtr($sSymbol, 'iM', 'Mi')) { if ($iLen == 2) { $iDoubleSymbol = 3 - 2 * ($iNum % 3); } $iDec += $iNum; $iPos += $iLen; # All symbols that represent 1eX may appear at maximum three times. All other symbols may only represent one time in a roman number. if (fmod(log10($iNum), 1) || ++$iCount == 3) { break; } } if ($iPos == $iStrLen) { break; } } # If there are symbols left, then the number was mallformed (following default rules (M = 1000 and i = 1000)). return $iPos == $iStrLen ? $iDec : 0; }
public function run() { $rows = []; $i = 0; foreach ($this->attributes as $attribute) { $rows[] = $this->renderAttribute($attribute, $i++); } $t = []; $len = count($rows); for ($j = 0; $j < $len; $j++) { if (fmod($j, $this->columns) == 0) { $rows[$j] = '<tr>' . $rows[$j]; } elseif (fmod($j, $this->columns) == $this->columns - 1) { $rows[$j] .= '</tr>'; } if ($j == $len - 1) { $_len = $this->columns - (fmod($j, $this->columns) + 1); for ($i = 0; $i < $_len; $i++) { $rows[$j] .= strtr($this->template, ['{label}' => ' ', '{value}' => ' ']); } $rows[$j] .= '</tr>'; } } $options = $this->options; $tag = ArrayHelper::remove($options, 'tag', 'table'); echo Html::tag($tag, implode("\n", $rows), $options); }
function myMethodHandler($progressValue, &$bar) { if (fmod($progressValue, 10) == 0) { echo "myMethodHandler -> progress value is = {$progressValue} <br/>\n"; } $bar->sleep(); }
public function convertIntToShortCode($id) { $id = intval($id); if ($id < 1) { throw new Exception("The ID is not a valid integer"); } $length = strlen(self::$chars); // make sure length of available characters is at // least a reasonable minimum - there should be at // least 10 characters if ($length < 10) { throw new Exception("Length of chars is too small"); } $code = ""; while ($id > $length - 1) { // determine the value of the next higher character // in the short code should be and prepend $code = self::$chars[fmod($id, $length)] . $code; // reset $id to remaining value to be converted $id = floor($id / $length); } // remaining value of $id is less than the length of // self::$chars $code = self::$chars[$id] . $code; return $code; }
function deciphering($string) { $letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; $letter_dict = str_split($letters); $rev_letter_dict = array_flip($letter_dict); $str_arr = str_split($string); $new_str_arr = array(); $last_str_arr = array(); foreach ($str_arr as $str) { $val = $rev_letter_dict[$str]; $new_str_arr[] = $val; } while (list($key, $value) = each($new_str_arr)) { if ($value < 15) { $value = $value + 26; $value = $value - $key - 1; $value = fmod($value, 10); } else { $value = $value - $key - 1; $value = fmod($value, 10); } $last_str_arr[] = $value; } $deciphering_num = implode('', $last_str_arr); return $deciphering_num; }
function timezones() { $list = DateTimeZone::listIdentifiers(); $data = array(); foreach ($list as $id => $zone) { $now = new DateTime(null, new DateTimeZone($zone)); $offset = $now->getOffset(); $offset_round = round(abs($offset / 3600), 2); $minutes = fmod($offset_round, 1); if ($minutes == 0) { $offset_label = $offset_round . ' '; } elseif ($minutes == 0.5) { $offset_label = (int) $offset_round . '.30'; } elseif ($minutes == 0.75) { $offset_label = (int) $offset_round . '.45'; } $sign = $offset > 0 ? '+' : '-'; if ($offset == 0) { $sign = ' '; $offset = ''; } $label = 'GMT' . $sign . $offset_label . ' ' . $zone; $data[$offset][$zone] = array('offset' => $offset, 'label' => $label, 'timezone_id' => $zone); } ksort($data); $timezones = array(); foreach ($data as $offsets) { ksort($offsets); foreach ($offsets as $zone) { $timezones[] = $zone; } } return $timezones; }
public static function parseSession($data) { $arr = explode('|', $data); foreach ($arr as $item) { $temp = explode(';', $item); $size = count($temp); // echo "size=>".$size."\r\n"; $temp2 = explode('}', $item); $size2 = count($temp2) - 1; // echo "size2=>".$size2."\n\r"; if ($size == 2) { $result[] = $temp[0]; $result[] = $temp[1]; } elseif ($size2 == 1) { $result[] = $temp2[0] . '}'; $result[] = $temp2[1]; } else { $result[] = $item; } } foreach ($result as $key => $value) { if (fmod($key, 2) == 0) { $result[$key] = "s:" . strlen($value) . ':"' . $value . '"'; } } // echo serialize($_SESSION)."<br />"; $serialize = "a:" . intval(count($result) / 2) . ":{" . implode(';', $result) . "}"; $serialize = str_replace('{};', '{}', $serialize); return unserialize($serialize); }
function random_float($min, $max) { $val = round($min + lcg_value() * abs($max - $min), 3); $bal = round(fmod($val, 0.005), 3); $val = $val - $bal; echo $val; }
/** * Constructor * * @param \PDOStatement $stmt * @param integer $rowCount total num of rows in $stmt * @param integer $tupleCount set to NULL to get all rows */ public function __construct(\PDOStatement $stmt, $rowCount, $tupleCount) { $this->rowCount = $rowCount; $this->tupleCount = $tupleCount; $this->stmt = $stmt; $this->stmt->setFetchMode(\PDO::FETCH_NUM); if (empty($this->tupleCount) || $this->rowCount < $this->tupleCount) { // get all rows $this->packageSize = 1; $this->tupleCount = $this->rowCount; } else { // summarize $this->packageSize = floor($this->rowCount / $this->tupleCount); $this->tupleCount = floor($this->rowCount / $this->packageSize); if (fmod($this->rowCount, $this->packageSize) > 0) { $this->tupleCount++; } } // skipping first reading, just for getting first timestamp, value is remembered list($this->from, $this->firstValue, $foo) = $this->stmt->fetch(); // ensure valid data range if we have 1 row only (not using iterator then) if ($this->from) { $this->to = $this->from; } }
public function process(LooPHP_EventLoop $event_loop, $timeout) { $read_resource_array = $this->_socket_array; $write_resource_array = NULL; $exception_resource_array = $this->_socket_array; $results = socket_select($read_resource_array, $write_resource_array, $exception_resource_array, is_null($timeout) ? NULL : floor($timeout), is_null($timeout) ? NULL : fmod($timeout, 1) * 1000000); if ($results === FALSE) { throw new Exception("stream_select failed"); } if ($results > 0) { foreach ($read_resource_array as $read_resource) { if ($this->_listen_socket === $read_resource) { $client_resource = @socket_accept($this->_listen_socket); socket_set_nonblock($client_resource); $this->_socket_array[(int) $client_resource] = $client_resource; $this->_socket_data[(int) $client_resource] = array("client_id" => NULL, "buffer" => ""); } else { $this->readClient($event_loop, $read_resource); } } foreach ($exception_resource_array as $exception_resource) { if ($this->_listen_socket === $read_resource) { throw new Exception("listen socket had exception"); } else { print "Socket had exception\n"; unset($this->_socket_array[(int) $exception_resource]); unset($this->_socket_data[(int) $exception_resource]); } } } return TRUE; }
public function find_time($minutes_after_midnight) { $hours = floor($minutes_after_midnight / 60); $minutes = fmod($minutes_after_midnight, 60); $time = "{$hours}" . ":" . "{$minutes}"; return $time; }
function random_int($min = PHP_INT_MIN, $max = PHP_INT_MAX) { if ($min >= $max) { trigger_error('Minimum value must be less than the maximum value', E_USER_WARNING); return false; } $umax = $max - $min; $result = random_bytes(PHP_INT_SIZE); if ($result === false) { return false; } $ULONG_MAX = PHP_INT_MAX - PHP_INT_MIN; $result = hexdec(bin2hex($result)); if ($umax === $ULONG_MAX) { return intval($result); } $umax++; if (($umax & $umax - 1) != 0) { $limit = $ULONG_MAX - fmod($ULONG_MAX, $umax) - 1; while ($result > $limit) { $result = random_bytes(PHP_INT_SIZE); if ($result === false) { return false; } $result = hexdec(bin2hex($result)); } } return intval(fmod($result, $umax) + $min); }
/** * verifica se o cpf � v�lido * * @param string $value cpf a ser validado * @return bool */ public function isValid($value) { $this->_setValue($value); if (!$this->_skipFormat && preg_match($this->_pattern, $value) == false) { $this->_error(self::INVALID_FORMAT); return false; } $digits = preg_replace('/[^\\d]+/i', '', $value); $firstSum = 0; $secondSum = 0; for ($i = 0; $i < 9; $i++) { $firstSum += $digits[$i] * (10 - $i); $secondSum += $digits[$i] * (11 - $i); } $firstDigit = 11 - fmod($firstSum, 11); if ($firstDigit >= 10) { $firstDigit = 0; } $secondSum = $secondSum + $firstDigit * 2; $secondDigit = 11 - fmod($secondSum, 11); if ($secondDigit >= 10) { $secondDigit = 0; } if (substr($digits, -2) != $firstDigit . $secondDigit) { $this->_error(self::INVALID_DIGITS); return false; } return true; }
public function format($timestamp, $format, DateTimeZone $timeZone = null) { $dateTime = new DateTime(); $dateTime->setTimestamp($timestamp); if (is_null($timeZone)) { $timeZone = new DateTimeZone(common_session_SessionManager::getSession()->getTimeZone()); } $dateTime->setTimezone($timeZone); switch ($format) { case \tao_helpers_Date::FORMAT_LONG: $formatString = 'd/m/Y H:i:s'; break; case \tao_helpers_Date::FORMAT_DATEPICKER: $formatString = 'Y-m-d H:i'; break; case \tao_helpers_Date::FORMAT_VERBOSE: $formatString = 'F j, Y, g:i:s a'; break; case \tao_helpers_Date::FORMAT_ISO8601: $milliseconds = str_replace('0.', '', sprintf('%0.3f', fmod($timestamp, 1))); $formatString = 'Y-m-d\\TH:i:s.' . $milliseconds; break; default: common_Logger::w('Unknown date format ' . $format . ' for ' . __FUNCTION__, 'TAO'); $formatString = ''; } return $dateTime->format($formatString); }
function get_gemology() { $name = $this->input->post('name'); $dob = $this->input->post('dob'); //Seperate the date,month,year from input $d = explode("-", $dob); $num = array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2); $n = 9; $dyy = fmod($d[0], $n); $dd1 = fmod($d[2], $n); $dd = $dd1 == 0 ? "9" : $dd1; $dm1 = ltrim($d[1], '0') - 1; $dm = $num[$dm1]; $dy = 8 - $dyy; //echo ($dd.'+'.$dm.'-'.$dy); //Calculate the total value with corresponding date,month and year values $luck = $dd + $dm - $dy; if ($luck <= 0) { $lucky = 9 + $luck; } else { if ($luck > 9) { $lucky = $luck - 9; } else { $lucky = $luck; } } // echo $lucky; //Select the descripton and stones based on lucky number $sql = "SELECT * FROM `gemology` WHERE gID = '{$lucky}'"; $query = $this->db->query($sql); $row1 = $query->result_array(); $row = json_encode($row1); //print the value print_r($row); }
function CircleDraw($lat_one, $long_one, $radius, $datasrc, $time) { //convert from degrees to radians $lat1 = deg2rad($lat_one); $long1 = deg2rad($long_one); $d = $radius; $d_rad = $d / 6378137; $hex = 0xc249255; $color = $datasrc * $hex; $out = "<name>Data Visualization</name>\n"; $out .= "<visibility>1</visibility>\n"; $out .= "<Placemark>\n"; $out .= "<name>Dilution for node " . $datasrc . " at " . $time . "</name>\n"; $out .= "<visibility>1</visibility>\n"; $out .= "<Style>\n"; $out .= "<geomColor>" . dechex($color) . "</geomColor>\n"; $out .= "<geomScale>1</geomScale></Style>\n"; $out .= "<LineString>\n"; $out .= "<coordinates>\n"; // loop through the array and write path linestrings for ($i = 0; $i <= 360; $i++) { $radial = deg2rad($i); $lat_rad = asin(sin($lat1) * cos($d_rad) + cos($lat1) * sin($d_rad) * cos($radial)); $dlon_rad = atan2(sin($radial) * sin($d_rad) * cos($lat1), cos($d_rad) - sin($lat1) * sin($lat_rad)); $lon_rad = fmod($long1 + $dlon_rad + M_PI, 2 * M_PI) - M_PI; $out .= rad2deg($lon_rad) . "," . rad2deg($lat_rad) . ",0 "; } $out .= "</coordinates>\n"; $out .= "</LineString>\n"; $out .= "</Placemark>\n"; return $out; }
function lefttime($second) { $times = ''; $day = floor($second / (3600 * 24)); $second = $second % (3600 * 24); //除去整天之后剩余的时间 $hour = floor($second / 3600); $second = $second - $hour * 3600; //除去整小时之后剩余的时间 $minute = floor($second / 60); $second = fmod(floatval($second), 60); //除去整分钟之后剩余的时间 if ($day) { $times = $day . '天'; } if ($hour) { $times .= $hour . '小时'; } if ($minute) { $times .= $minute . '分'; } if ($second) { $times .= $second . '秒'; } //返回字符串 return $times; }
public function generateTournoiAction($id) { //Récupération de l'objet Tournoi $tournoi = $this->getDoctrine()->getRepository('TiremoidlaTournoiBundle:Tournoi')->find($id); //Récupération de la liste des épreuves du tournoi $listeEpreuve = ""; $message = ""; $listeEpreuve = $this->getDoctrine()->getRepository('TiremoidlaEpreuveBundle:Epreuve')->findBy(array('tournoi' => $id)); $message = ""; foreach ($listeEpreuve as $epreuve) { $inscrits = $epreuve->getNombreInscrits(); $ntp = $epreuve->getNtp(); $nbPoule = floor($inscrits / $ntp); if (fmod($inscrits, $ntp) != 0 && fmod($inscrits, $ntp) != $ntp - 1 && fmod($inscrits, $ntp) != $ntp + 1) { $nbPoule--; $qqtTireur = $ntp * $nbPoule; if ($inscrits - $qqtTireur != $ntp - 1 && $inscrits - $qqtTireur != $ntp + 1) { $message .= $this->calculPoule($inscrits, $ntp, $nbPoule); } else { //ok $message .= $inscrits - $qqtTireur; } /*foreach($this->calculPoule($inscrits,$ntp,$nbPoule) as $tab=>$key){ $message = "--".$key." : ".$tab; }*/ } } return $this->render('TiremoidlaTournoiBundle:Default:visualiserTournoi.html.twig', array('tournoi' => $tournoi, 'listeEpreuve' => $listeEpreuve, 'message' => $message)); }