当前位置: 首页>>代码示例>>PHP>>正文


PHP fmod函数代码示例

本文整理汇总了PHP中fmod函数的典型用法代码示例。如果您正苦于以下问题:PHP fmod函数的具体用法?PHP fmod怎么用?PHP fmod使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了fmod函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: process

 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;
 }
开发者ID:Wordi,项目名称:LooPHP,代码行数:32,代码来源:sockets.php

示例2: isValid

 /**
  * 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;
 }
开发者ID:cityware,项目名称:city-form,代码行数:41,代码来源:Cpf.php

示例3: TL

 /**
  * 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);
 }
开发者ID:tehmaestro,项目名称:google-translate-php,代码行数:42,代码来源:GoogleTokenGenerator.php

示例4: ReadNumber

 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;
 }
开发者ID:themesanasang,项目名称:salary,代码行数:25,代码来源:ReportController.php

示例5: formatPrice

 /**
  * 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;
 }
开发者ID:AppChecker,项目名称:onxshop,代码行数:29,代码来源:roundel_css.php

示例6: int_to_words

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;
}
开发者ID:NetPainter,项目名称:aspis,代码行数:60,代码来源:test_www_string-number-to-words.php

示例7: do_main

 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;
 }
开发者ID:5haman,项目名称:knowledgetree,代码行数:29,代码来源:deletedDocuments.php

示例8: isValid

 /**
  * 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;
 }
开发者ID:rodrigosebold,项目名称:zfb,代码行数:37,代码来源:Cnpj.php

示例9: ex3

 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
 }
开发者ID:hoenirvili,项目名称:cn,代码行数:34,代码来源:HomeWork1.php

示例10: checksum

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;
}
开发者ID:rafuch0,项目名称:lljs-pagerank,代码行数:31,代码来源:pagerank.php

示例11: generate_calendar

 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;
 }
开发者ID:phpwax,项目名称:wildfire.events,代码行数:33,代码来源:Calendar.php

示例12: crc

 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];
 }
开发者ID:mamtou,项目名称:wavephp,代码行数:7,代码来源:Common.php

示例13: toDecimal

 /**
  * 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;
 }
开发者ID:ricardo21,项目名称:test,代码行数:39,代码来源:class.php

示例14: run

 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}' => '&nbsp;', '{value}' => '&nbsp;']);
             }
             $rows[$j] .= '</tr>';
         }
     }
     $options = $this->options;
     $tag = ArrayHelper::remove($options, 'tag', 'table');
     echo Html::tag($tag, implode("\n", $rows), $options);
 }
开发者ID:itzj86,项目名称:yii2-dwz,代码行数:27,代码来源:DetailView.php

示例15: myMethodHandler

 function myMethodHandler($progressValue, &$bar)
 {
     if (fmod($progressValue, 10) == 0) {
         echo "myMethodHandler -> progress value is = {$progressValue} <br/>\n";
     }
     $bar->sleep();
 }
开发者ID:Ogwang,项目名称:sainp,代码行数:7,代码来源:method_callback.php


注:本文中的fmod函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。