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


PHP min函数代码示例

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


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

示例1: truncate

 /**
  * Truncates a string to the given length.  It will optionally preserve
  * HTML tags if $is_html is set to true.
  *
  * @param   string  $string        the string to truncate
  * @param   int     $limit         the number of characters to truncate too
  * @param   string  $continuation  the string to use to denote it was truncated
  * @param   bool    $is_html       whether the string has HTML
  * @return  string  the truncated string
  */
 public static function truncate($string, $limit, $continuation = '...', $is_html = false)
 {
     $offset = 0;
     $tags = array();
     if ($is_html) {
         // Handle special characters.
         preg_match_all('/&[a-z]+;/i', strip_tags($string), $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER);
         foreach ($matches as $match) {
             if ($match[0][1] >= $limit) {
                 break;
             }
             $limit += static::length($match[0][0]) - 1;
         }
         // Handle all the html tags.
         preg_match_all('/<[^>]+>([^<]*)/', $string, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER);
         foreach ($matches as $match) {
             if ($match[0][1] - $offset >= $limit) {
                 break;
             }
             $tag = static::sub(strtok($match[0][0], " \t\n\r\v>"), 1);
             if ($tag[0] != '/') {
                 $tags[] = $tag;
             } elseif (end($tags) == static::sub($tag, 1)) {
                 array_pop($tags);
             }
             $offset += $match[1][1] - $match[0][1];
         }
     }
     $new_string = static::sub($string, 0, $limit = min(static::length($string), $limit + $offset));
     $new_string .= static::length($string) > $limit ? $continuation : '';
     $new_string .= count($tags = array_reverse($tags)) ? '</' . implode('></', $tags) . '>' : '';
     return $new_string;
 }
开发者ID:huglester,项目名称:pyrocms-helpers,代码行数:43,代码来源:Str.php

示例2: upload

 /**
  * @brief Accion que se encarga de manipular el proceso de guardar
  * un archivo en el servidor
  * @param array $allowedExtensions Arreglo de extensiones validas para el archivo
  * @param int $sizeLimit Tamaño maximo permitido del fichero que se sube
  */
 function upload($allowedExtensions, $sizeLimit = 10485760)
 {
     jimport('Amadeus.Util.Uploader');
     $media =& JComponentHelper::getParams('com_media');
     $postSize = $this->toBytes(ini_get('post_max_size'));
     $uploadSize = $this->toBytes(ini_get('upload_max_filesize'));
     $mediaSize = (int) $media->get('upload_maxsize');
     // Se selecciona el minimo tamaño válido para un fichero, de acuerdo
     // a los valores configurados en el php, el joomla y el componente.
     $sizeLimit = min($postSize, $uploadSize, $mediaSize, $sizeLimit);
     // Se alamacena la imagen en la ruta especificada
     $uploader = new qqFileUploader($allowedExtensions, $sizeLimit);
     $result = $uploader->handleUpload(JPATH_SITE . '/tmp/', true);
     if (!isset($result['error'])) {
         jimport('Amadeus.Util.Validation');
         $file = $uploader->getName();
         $result = AmadeusUtilValidation::isValidFile($file, $only_image);
         if (isset($result['error'])) {
             jimport('joomla.filesystem.file');
             if (!JFile::delete($file)) {
                 $result = array('error' => JText::_('DELETEERROR'));
             }
         } else {
             $this->_file = $file;
         }
     }
     return $result;
 }
开发者ID:jmangarret,项目名称:webtuagencia24,代码行数:34,代码来源:File.php

示例3: humanReadableBytes

 /**
  * Get human readable file size, quick and dirty.
  * 
  * @todo Improve i18n support.
  *
  * @param int $bytes
  * @param string $format
  * @param int|null $decimal_places
  * @return string Human readable string with file size.
  */
 public static function humanReadableBytes($bytes, $format = "en", $decimal_places = null)
 {
     switch ($format) {
         case "sv":
             $dec_separator = ",";
             $thousands_separator = " ";
             break;
         default:
         case "en":
             $dec_separator = ".";
             $thousands_separator = ",";
             break;
     }
     $b = (int) $bytes;
     $s = array('B', 'kB', 'MB', 'GB', 'TB');
     if ($b <= 0) {
         return "0 " . $s[0];
     }
     $con = 1024;
     $e = (int) log($b, $con);
     $e = min($e, count($s) - 1);
     $v = $b / pow($con, $e);
     if ($decimal_places === null) {
         $decimal_places = max(0, 2 - (int) log($v, 10));
     }
     return number_format($v, !$e ? 0 : $decimal_places, $dec_separator, $thousands_separator) . ' ' . $s[$e];
 }
开发者ID:varvanin,项目名称:currycms,代码行数:37,代码来源:Util.php

示例4: transfer

 /**
  * {@inheritdoc}
  */
 protected function transfer()
 {
     while (!$this->stopped && !$this->source->isConsumed()) {
         if ($this->source->getContentLength() && $this->source->isSeekable()) {
             // If the stream is seekable and the Content-Length known, then stream from the data source
             $body = new ReadLimitEntityBody($this->source, $this->partSize, $this->source->ftell());
         } else {
             // We need to read the data source into a temporary buffer before streaming
             $body = EntityBody::factory();
             while ($body->getContentLength() < $this->partSize && $body->write($this->source->read(max(1, min(10 * Size::KB, $this->partSize - $body->getContentLength()))))) {
             }
         }
         // @codeCoverageIgnoreStart
         if ($body->getContentLength() == 0) {
             break;
         }
         // @codeCoverageIgnoreEnd
         $params = $this->state->getUploadId()->toParams();
         $command = $this->client->getCommand('UploadPart', array_replace($params, array('PartNumber' => count($this->state) + 1, 'Body' => $body, 'ContentMD5' => (bool) $this->options['part_md5'], Ua::OPTION => Ua::MULTIPART_UPLOAD)));
         // Notify observers that the part is about to be uploaded
         $eventData = $this->getEventData();
         $eventData['command'] = $command;
         $this->dispatch(self::BEFORE_PART_UPLOAD, $eventData);
         // Allow listeners to stop the transfer if needed
         if ($this->stopped) {
             break;
         }
         $response = $command->getResponse();
         $this->state->addPart(UploadPart::fromArray(array('PartNumber' => count($this->state) + 1, 'ETag' => $response->getHeader('ETag', true), 'Size' => $body->getContentLength(), 'LastModified' => gmdate(DateFormat::RFC2822))));
         // Notify observers that the part was uploaded
         $this->dispatch(self::AFTER_PART_UPLOAD, $eventData);
     }
 }
开发者ID:romainneutron,项目名称:aws-sdk-php,代码行数:36,代码来源:SerialTransfer.php

示例5: smarty_modifier_truncate

/**
 * Smarty truncate modifier plugin
 * Type:     modifier<br>
 * Name:     truncate<br>
 * Purpose:  Truncate a string to a certain length if necessary,
 *               optionally splitting in the middle of a word, and
 *               appending the $etc string or inserting $etc into the middle.
 *
 * @link   http://smarty.php.net/manual/en/language.modifier.truncate.php truncate (Smarty online manual)
 * @author Monte Ohrt <monte at ohrt dot com>
 *
 * @param string  $string      input string
 * @param integer $length      length of truncated text
 * @param string  $etc         end string
 * @param boolean $break_words truncate at word boundary
 * @param boolean $middle      truncate in the middle of text
 *
 * @return string truncated string
 */
function smarty_modifier_truncate($string, $length = 80, $etc = '...', $break_words = false, $middle = false)
{
    if ($length == 0) {
        return '';
    }
    if (Smarty::$_MBSTRING) {
        if (mb_strlen($string, Smarty::$_CHARSET) > $length) {
            $length -= min($length, mb_strlen($etc, Smarty::$_CHARSET));
            if (!$break_words && !$middle) {
                $string = preg_replace('/\\s+?(\\S+)?$/' . Smarty::$_UTF8_MODIFIER, '', mb_substr($string, 0, $length + 1, Smarty::$_CHARSET));
            }
            if (!$middle) {
                return mb_substr($string, 0, $length, Smarty::$_CHARSET) . $etc;
            }
            return mb_substr($string, 0, $length / 2, Smarty::$_CHARSET) . $etc . mb_substr($string, -$length / 2, $length, Smarty::$_CHARSET);
        }
        return $string;
    }
    // no MBString fallback
    if (isset($string[$length])) {
        $length -= min($length, strlen($etc));
        if (!$break_words && !$middle) {
            $string = preg_replace('/\\s+?(\\S+)?$/', '', substr($string, 0, $length + 1));
        }
        if (!$middle) {
            return substr($string, 0, $length) . $etc;
        }
        return substr($string, 0, $length / 2) . $etc . substr($string, -$length / 2);
    }
    return $string;
}
开发者ID:TheTypoMaster,项目名称:SPHERE-Framework,代码行数:50,代码来源:modifier.truncate.php

示例6: do_main

 function do_main()
 {
     $notifications = (array) KTNotification::getList(array("user_id = ?", $this->oUser->getId()));
     $num_notifications = count($notifications);
     $PAGE_SIZE = 5;
     $page = (int) KTUtil::arrayGet($_REQUEST, 'page', 0);
     $page_count = ceil($num_notifications / $PAGE_SIZE);
     if ($page >= $page_count) {
         $page = $page_count - 1;
     }
     if ($page < 0) {
         $page = 0;
     }
     // slice the notification array.
     $notifications = array_slice($notifications, $page * $PAGE_SIZE, $PAGE_SIZE);
     // prepare the batch html.  easier to do this here than in the template.
     $batch = array();
     for ($i = 0; $i < $page_count; $i++) {
         if ($i == $page) {
             $batch[] = sprintf("<strong>%d</strong>", $i + 1);
         } else {
             $batch[] = sprintf('<a href="%s">%d</a>', KTUtil::addQueryStringSelf($this->meldPersistQuery(array("page" => $i), "main", true)), $i + 1);
         }
     }
     $batch_html = implode(' &middot; ', $batch);
     $count_string = sprintf(_kt("Showing Notifications %d - %d of %d"), $page * $PAGE_SIZE + 1, min(($page + 1) * $PAGE_SIZE, $num_notifications), $num_notifications);
     $this->oPage->setTitle(_kt("Items that require your attention"));
     $oTemplate =& $this->oValidator->validateTemplate("ktcore/misc/notification_overflow");
     $oTemplate->setData(array('count_string' => $count_string, 'batch_html' => $batch_html, 'notifications' => $notifications));
     return $oTemplate->render();
 }
开发者ID:5haman,项目名称:knowledgetree,代码行数:31,代码来源:KTMiscPages.php

示例7: writeFile

 /**
  * Uploads file to FTP server.
  * @return void
  */
 public function writeFile($local, $remote, callable $progress = NULL)
 {
     $size = max(filesize($local), 1);
     $retry = self::RETRIES;
     upload:
     $blocks = 0;
     do {
         if ($progress) {
             $progress(min($blocks * self::BLOCK_SIZE / $size, 100));
         }
         try {
             $ret = $blocks === 0 ? $this->ftp('nb_put', $remote, $local, FTP_BINARY) : $this->ftp('nb_continue');
         } catch (FtpException $e) {
             @ftp_close($this->connection);
             // intentionally @
             $this->connect();
             if (--$retry) {
                 goto upload;
             }
             throw new FtpException("Cannot upload file {$local}, number of retries exceeded. Error: {$e->getMessage()}");
         }
         $blocks++;
     } while ($ret === FTP_MOREDATA);
     if ($progress) {
         $progress(100);
     }
 }
开发者ID:hranicka,项目名称:dg-ftp-deployment,代码行数:31,代码来源:FtpServer.php

示例8: writeInfo

 /**
  * Render the information header for the view
  * 
  * @param string $title
  * @param string $title
  */
 public function writeInfo($title, $subtitle, $description = false)
 {
     echo wordwrap(strtoupper($title), 100) . "\n";
     echo wordwrap($subtitle, 100) . "\n";
     echo str_repeat('-', min(100, max(strlen($title), strlen($subtitle)))) . "\n";
     echo wordwrap($description, 100) . "\n\n";
 }
开发者ID:SustainableCoastlines,项目名称:loveyourwater,代码行数:13,代码来源:CliDebugView.php

示例9: formatColor

 public function formatColor(\OttawaDeveloper\Tools\ColorAnalyzer\Color $color)
 {
     $colorValues = array('red' => $color->red() / 255, 'green' => $color->green() / 255, 'blue' => $color->blue() / 255);
     $minimumValue = min($colorValues);
     $maximumValue = max($colorValues);
     $luminescence = round(($minimumValue + $maximumValue) / 2, 2);
     if ($minimumValue == $maximumValue) {
         return $this->formatHslColor(0, 0, $luminescence, $color->alpha());
     }
     $colorRange = $maximumValue - $minimumValue;
     $saturation = $colorRange;
     if ($luminescence < 0.5) {
         $saturation /= $maximumValue + $minimumValue;
     } else {
         $saturation /= 2 - $colorRange;
     }
     $hue = 0;
     if ($colorValues['red'] >= $colorValues['blue'] && $colorValues['red'] >= $colorValues['green']) {
         $hue = ($colorValues['green'] - $colorValues['blue']) / $colorRange;
     } elseif ($colorValues['green'] >= $colorValues['blue'] && $colorValues['green'] >= $colorValues['red']) {
         $hue = 2 + ($colorValues['blue'] - $colorValues['red']) / $colorRange;
     } else {
         $hue = 4 + ($colorValues['red'] - $colorValues['green']) / $colorRange;
     }
     return $this->formatHslColor($hue * 60, $saturation, $luminescence, $color->alpha());
 }
开发者ID:ottawadeveloper,项目名称:coloranalyzer,代码行数:26,代码来源:HslProcessor.php

示例10: toString

 /**
  * Returns "..." in place of common prefix and "..." in
  * place of common suffix between expected and actual.
  *
  * @return string
  * @access public
  */
 public function toString()
 {
     $end = min(strlen($this->expected), strlen($this->actual));
     $i = 0;
     $j = strlen($this->expected) - 1;
     $k = strlen($this->actual) - 1;
     for (; $i < $end; $i++) {
         if ($this->expected[$i] != $this->actual[$i]) {
             break;
         }
     }
     for (; $k >= $i && $j >= $i; $k--, $j--) {
         if ($this->expected[$j] != $this->actual[$k]) {
             break;
         }
     }
     if ($j < $i && $k < $i) {
         $expected = $this->expected;
         $actual = $this->actual;
     } else {
         $expected = substr($this->expected, $i, $j + 1 - $i);
         $actual = substr($this->actual, $i, $k + 1 - $i);
         if ($i <= $end && $i > 0) {
             $expected = '...' . $expected;
             $actual = '...' . $actual;
         }
         if ($j < strlen($this->expected) - 1) {
             $expected .= '...';
         }
         if ($k < strlen($this->actual) - 1) {
             $actual .= '...';
         }
     }
     return PHPUnit2_Framework_Assert::format($expected, $actual, parent::getMessage());
 }
开发者ID:nateirwin,项目名称:custom-historic,代码行数:42,代码来源:ComparisonFailure.php

示例11: nuage_tags

function nuage_tags($limit = 30, $id_cat = 0)
{
    $list_tags = array();
    $count_tags = array();
    $limit_sql = $limit != 0 ? ' LIMIT ' . intval($limit) : '';
    $where_cat = $id_cat != 0 ? ' AND n_id_cat = ' . intval($id_cat) : '';
    $rqt_tags = Nw::$DB->query('SELECT c_id, c_couleur, c_nom, t_id_news, t_tag, COUNT(t_tag) AS nbr_tags, n_id_cat FROM ' . Nw::$prefix_table . 'tags
        LEFT JOIN ' . Nw::$prefix_table . 'news ON t_id_news = n_id
        LEFT JOIN ' . Nw::$prefix_table . 'categories ON c_id = n_id_cat
    WHERE n_etat = 3' . $where_cat . '
    GROUP BY t_tag ORDER BY t_tag ASC ' . $limit_sql) or Nw::$DB->trigger(__LINE__, __FILE__);
    while ($donnees = $rqt_tags->fetch_assoc()) {
        $list_tags[$donnees['t_tag']] = $donnees;
        $count_tags[$donnees['t_tag']] = $donnees['nbr_tags'];
    }
    $max_size = 200;
    $min_size = 100;
    $max_qty = 0;
    $min_qty = 0;
    if (count($count_tags) > 0) {
        $max_qty = max(array_values($count_tags));
        $min_qty = min(array_values($count_tags));
    }
    $spread = $max_qty - $min_qty;
    if (0 == $spread) {
        $spread = 1;
    }
    $step = ($max_size - $min_size) / $spread;
    foreach ($list_tags as $tags) {
        $list_tags[$tags['t_tag']]['size'] = floor($min_size + ($tags['nbr_tags'] - $min_qty) * $step);
    }
    return $list_tags;
}
开发者ID:shiooooooookun,项目名称:Nouweo_PHP,代码行数:33,代码来源:nuage_tags.php

示例12: upClass

 /**
  * Migrate records of a single class
  *
  * @param string $class
  * @param null|string $stage
  */
 protected function upClass($class)
 {
     if (!class_exists($class)) {
         return;
     }
     if (is_subclass_of($class, 'SiteTree')) {
         $items = SiteTree::get()->filter('ClassName', $class);
     } else {
         $items = $class::get();
     }
     if ($count = $items->count()) {
         $this->message(sprintf('Migrating %s legacy %s records.', $count, $class));
         foreach ($items as $item) {
             $cancel = $item->extend('onBeforeUp');
             if ($cancel && min($cancel) === false) {
                 continue;
             }
             /**
              * @var MigratableObject $item
              */
             $result = $item->up();
             $this->message($result);
             $item->extend('onAfterUp');
         }
     }
 }
开发者ID:helpfulrobot,项目名称:silverstripe-blog,代码行数:32,代码来源:BlogMigrationTask.php

示例13: execute

 public function execute(array $deferred, array $data, $targetRunTime, &$status)
 {
     $data = array_merge(array('position' => 0, 'batch' => 100, 'delete' => false), $data);
     $data['batch'] = max(1, $data['batch']);
     /* @var $statsModel XenForo_Model_Stats */
     $statsModel = XenForo_Model::create('XenForo_Model_Stats');
     if ($data['position'] == 0) {
         // delete old stats cache if required
         if (!empty($data['delete'])) {
             $statsModel->deleteStats();
         }
         // an appropriate date from which to start... first thread, or earliest user reg?
         $data['position'] = min(XenForo_Model::create('XenForo_Model_Thread')->getEarliestThreadDate(), XenForo_Model::create('XenForo_Model_User')->getEarliestRegistrationDate());
         // start on a 24 hour increment point
         $data['position'] = $data['position'] - $data['position'] % 86400;
     } else {
         if ($data['position'] > XenForo_Application::$time) {
             return true;
         }
     }
     $endPosition = $data['position'] + $data['batch'] * 86400;
     $statsModel->buildStatsData($data['position'], $endPosition);
     $data['position'] = $endPosition;
     $actionPhrase = new XenForo_Phrase('rebuilding');
     $typePhrase = new XenForo_Phrase('daily_statistics');
     $status = sprintf('%s... %s (%s)', $actionPhrase, $typePhrase, XenForo_Locale::date($data['position'], 'absolute'));
     return $data;
 }
开发者ID:namgiangle90,项目名称:tokyobaito,代码行数:28,代码来源:DailyStats.php

示例14: getTweets

function getTweets($notification)
{
    $twitter = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
    $date = $notification['date'];
    $keywords = array("sirene", "gevaar", "ongeluk", "ambulance", "ziekenwagen", "ongeval", "gewond", "letsel", "brand", "vlam", "vuur", "brandweer", "blus", "water", "overval", "politie", "dief", "wapen", "letsel", "inbraak", "schiet", "misdrijf");
    $start_date = "since:" . date(DATE_FORMAT, $date);
    $end_date = "until:" . date(DATE_FORMAT, strtotime("+1 day", $date));
    //$search_string = $notification['town'] . " " . implode(" OR ", $keywords) . " -p2000 " . $start_date . " " . $end_date;
    $search_string = implode(" OR ", KEYWORDS_GEN) . " -p2000 -RT " . $start_date . " " . $end_date;
    $cur_min = min(100, $notification["num_tweets"]);
    $params = array('q' => $search_string, 'lang' => 'nl', 'count' => $cur_min);
    //$statuses = json_encode((array)$twitter->get("search/tweets", $params));
    $temp = (array) $twitter->get("search/tweets", $params);
    $statuses = $temp["statuses"];
    $total_num = count($statuses);
    $num_stat = count($statuses);
    $min_id = $statuses[$num_stat - 1]->id;
    while ($total_num < $notification["num_tweets"] && $num_stat >= $cur_min) {
        $cur_min = min($notification["num_tweets"] - $total_num, 100);
        $params = array('q' => $search_string, 'lang' => 'nl', 'count' => $cur_min, 'max_id' => $min_id);
        $new_temp = (array) $twitter->get("search/tweets", $params);
        $new_stat = $new_temp["statuses"];
        $num_stat = count($new_stat);
        $total_num = $total_num + $num_stat;
        $min_id = $new_stat[$num_stat - 1]->id;
        $statuses = array_merge($statuses, $new_stat);
    }
    //What do I do with the statuses?
    return json_encode($statuses);
}
开发者ID:Bram9205,项目名称:WebInfo,代码行数:30,代码来源:get_twitter.php

示例15: Get

 function Get($rss_url, $rss_feed_id)
 {
     $output = '';
     if (!isset($this->num_results)) {
         $this->num_results = 5;
     }
     if (!isset($this->description)) {
         $this->description = FALSE;
     }
     $result = $this->Parse($rss_url);
     if ($result && $result['items_count'] == 0) {
         return null;
     } else {
         if ($result) {
             $output = "<ul class='rss_feed'>";
             for ($i = 0; $i < min($this->num_results, $result['items_count']); $i++) {
                 $output .= "<li><a href='" . $result['items'][$i]['link'] . "' target='_new'>" . $result['items'][$i]['title'] . "</a>";
                 if ($this->description) {
                     $output .= "<br />" . $result['items'][$i]['description'];
                 }
                 $output .= "</li>\n";
             }
             $output .= "</ul>\n";
         } elseif (file_exists($cache_file)) {
             touch($cache_file);
         } else {
             //create an empty file
             if ($f = @fopen($cache_file, 'w')) {
                 fclose($f);
             }
         }
     }
     return $output;
 }
开发者ID:genaromendezl,项目名称:ATutor,代码行数:34,代码来源:lastRSS.php


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