本文整理汇总了PHP中ceil函数的典型用法代码示例。如果您正苦于以下问题:PHP ceil函数的具体用法?PHP ceil怎么用?PHP ceil使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ceil函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _str_pad
/**
* utf8::str_pad
*
* @package Core
* @author Kohana Team
* @copyright (c) 2007 Kohana Team
* @copyright (c) 2005 Harry Fuecks
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
*/
function _str_pad($str, $final_str_length, $pad_str = ' ', $pad_type = STR_PAD_RIGHT)
{
if (utf8::is_ascii($str) and utf8::is_ascii($pad_str)) {
return str_pad($str, $final_str_length, $pad_str, $pad_type);
}
$str_length = utf8::strlen($str);
if ($final_str_length <= 0 or $final_str_length <= $str_length) {
return $str;
}
$pad_str_length = utf8::strlen($pad_str);
$pad_length = $final_str_length - $str_length;
if ($pad_type == STR_PAD_RIGHT) {
$repeat = ceil($pad_length / $pad_str_length);
return utf8::substr($str . str_repeat($pad_str, $repeat), 0, $final_str_length);
}
if ($pad_type == STR_PAD_LEFT) {
$repeat = ceil($pad_length / $pad_str_length);
return utf8::substr(str_repeat($pad_str, $repeat), 0, floor($pad_length)) . $str;
}
if ($pad_type == STR_PAD_BOTH) {
$pad_length /= 2;
$pad_length_left = floor($pad_length);
$pad_length_right = ceil($pad_length);
$repeat_left = ceil($pad_length_left / $pad_str_length);
$repeat_right = ceil($pad_length_right / $pad_str_length);
$pad_left = utf8::substr(str_repeat($pad_str, $repeat_left), 0, $pad_length_left);
$pad_right = utf8::substr(str_repeat($pad_str, $repeat_right), 0, $pad_length_left);
return $pad_left . $str . $pad_right;
}
trigger_error('utf8::str_pad: Unknown padding type (' . $type . ')', E_USER_ERROR);
}
示例2: getLocation
function getLocation($str)
{
$array_size = intval(substr($str, 0, 1));
// 拆成的行数
$code = substr($str, 1);
// 加密后的串
$len = strlen($code);
$subline_size = $len % $array_size;
// 满字符的行数
$result = array();
$deurl = "";
for ($i = 0; $i < $array_size; $i += 1) {
if ($i < $subline_size) {
array_push($result, substr($code, 0, ceil($len / $array_size)));
$code = substr($code, ceil($len / $array_size));
} else {
array_push($result, substr($code, 0, ceil($len / $array_size) - 1));
$code = substr($code, ceil($len / $array_size) - 1);
}
}
for ($i = 0; $i < ceil($len / $array_size); $i += 1) {
for ($j = 0; $j < count($result); $j += 1) {
$deurl = $deurl . "" . substr($result[$j], $i, 1);
}
}
return str_replace("^", "0", urldecode($deurl));
}
示例3: page_navi
function page_navi($before = '', $after = '')
{
global $wpdb, $wp_query;
$request = $wp_query->request;
$posts_per_page = intval(get_query_var('posts_per_page'));
$paged = intval(get_query_var('paged'));
$numposts = $wp_query->found_posts;
$max_page = $wp_query->max_num_pages;
if ($numposts <= $posts_per_page) {
return;
}
if (empty($paged) || $paged == 0) {
$paged = 1;
}
$pages_to_show = 3;
$pages_to_show_minus_1 = $pages_to_show - 1;
$half_page_start = floor($pages_to_show_minus_1 / 2);
$half_page_end = ceil($pages_to_show_minus_1 / 2);
$start_page = $paged - $half_page_start;
if ($start_page <= 0) {
$start_page = 1;
}
$end_page = $paged + $half_page_end;
if ($end_page - $start_page != $pages_to_show_minus_1) {
$end_page = $start_page + $pages_to_show_minus_1;
}
if ($end_page > $max_page) {
$start_page = $max_page - $pages_to_show_minus_1;
$end_page = $max_page;
}
if ($start_page <= 0) {
$start_page = 1;
}
echo $before . '<div class="pagination_wrapper"><ul class="pagination">' . "";
if ($paged > 1) {
$first_page_text = "First";
echo '<li class="prev"><a href="' . get_pagenum_link() . '" title="First">' . $first_page_text . '</a></li>';
}
$prevposts = get_previous_posts_link('Prev');
if ($prevposts) {
echo '<li>' . $prevposts . '</li>';
} else {
echo '<li class="disabled"><a href="#">Prev</a></li>';
}
for ($i = $start_page; $i <= $end_page; $i++) {
if ($i == $paged) {
echo '<li class="active"><a href="#">' . $i . '</a></li>';
} else {
echo '<li><a href="' . get_pagenum_link($i) . '">' . $i . '</a></li>';
}
}
if ($end_page < $max_page) {
$last_page_text = $max_page;
echo '<li class="next"><a href="' . get_pagenum_link($max_page) . '" title="Last">' . $last_page_text . '</a></li>';
}
echo '<li class="">';
next_posts_link('Next');
echo '</li>';
echo '</ul></div>' . $after . "";
}
示例4: mostrarPost
public function mostrarPost($page = 1)
{
// traemos la cantidad de registros para el paginador
$registros = DB::table('post')->join('temas', 'post_tema', '=', 'temas.tema_id')->where('post_tipo', 'ENTRADA')->orderBy('post_fec', 'desc')->get();
$totalRegistros = count($registros);
//die("totalRegistros ".$totalRegistros); //16
$paginador = 15;
// Parametrizarlo desde DB
$cantPagina = $totalRegistros / $paginador;
//die("cantPagina ".$cantPagina); //1.066
$cantPagina = ceil($cantPagina);
//die("cantidad de paginas ".$cantPagina); //2
if ($page != 1) {
$comienzo = $page * $paginador - $paginador + 1;
// ((2*15)-15+1);
// (30)-14
// comenzara en la 16, pagina 2 y asi sucesivamente..
} else {
$comienzo = 1;
}
$final = $page * $paginador;
$post = DB::table('post')->join('temas', 'post_tema', '=', 'temas.tema_id')->where('post_tipo', 'ENTRADA')->orderBy('post_fec', 'desc')->skip($comienzo - 1)->take($final)->get();
//
if (count($post) < 1) {
$error = "No hay más resultados para mostrar.";
} else {
$error = "";
}
$tema = DB::table('post as p')->select('tm.tema_txt', 'tm.tema_img')->distinct()->join('usuarios as u', 'p.post_usu', '=', 'u.usuarios_id')->join('temas as tm', 'p.post_tema', '=', 'tm.tema_id')->orderBy('tm.tema_txt', 'asc')->get();
// Retornamos todos los datos
$entradas = DB::table('post as p')->select('p.*', 'u.usuarios_name', 'tm.tema_txt')->join('usuarios as u', 'p.post_usu', '=', 'u.usuarios_id')->join('temas as tm', 'p.post_tema', '=', 'tm.tema_id')->orderBy('p.post_fec', 'desc')->get();
return View::make('index', array('post' => $post, 'temas' => $tema, 'cantidadPag' => $cantPagina, 'errores' => $error, 'entradas' => $entradas));
}
示例5: lists
public function lists($productId)
{
if (IS_AJAX) {
$page_size = 10;
$page = I('page', 1, 'intval');
$start = ($page - 1) * $page_size;
$map = array('product_id' => $productId, 'status' => 1);
$ProductBid = M('ProductBid');
$total_count = $ProductBid->where($map)->count();
if ($total_count) {
$total_page = ceil($total_count / $page_size);
$bid_list = $ProductBid->where($map)->order('bid_id desc')->limit($start . ',' . $page_size)->select();
$User = M('User');
foreach ($bid_list as $key => $value) {
$bid_list[$key]['user_info'] = $User->find($value['user_id']);
}
$this->assign('bid_list', $bid_list);
$product_info = M('Product')->where($map)->find();
$this->assign('product_info', $product_info);
$range_price = $product_info['range_price'];
$content = $this->fetch('ajaxLists');
if ($product_info['product_type'] == 3) {
$value = array('info' => array('currentPrice' => $product_info['range_price'], 'bidPrice' => $product_info['range_price'], 'lastId' => 1), 'htmlString' => $content, 'isNextPage' => $total_page == 1 || $total_page == $page ? false : true, 'page' => $page, 'pageSize' => $page_size, 'totalCount' => $total_count, 'totalPage' => $total_page);
} else {
$max_bid_price = $ProductBid->where($map)->max('bid_price');
$value = array('info' => array('currentPrice' => $max_bid_price, 'bidPrice' => $max_bid_price + $range_price, 'lastId' => 1), 'htmlString' => $content, 'isNextPage' => $total_page == 1 || $total_page == $page ? false : true, 'page' => $page, 'pageSize' => $page_size, 'totalCount' => $total_count, 'totalPage' => $total_page);
}
} else {
$value = array('htmlString' => '', 'isNextPage' => false, 'page' => $page, 'pageSize' => $page_size, 'totalCount' => $total_count, 'totalPage' => 1);
}
$this->resultSuccess('加载中...', $value);
} else {
//$this->display();
}
}
示例6: LoadEquipsAndExtraInfo
private function LoadEquipsAndExtraInfo($locale)
{
$db = ConnectCharacterDatabase($locale);
$equipslot = 14;
$nameslot = 21;
if ($this->petslot == 2) {
$equipslot = 30;
$nameslot = 31;
} elseif ($this->petslot == 3) {
$equipslot = 38;
$nameslot = 39;
}
$this->equip = -1;
$this->nametag = -1;
$q = $db->query("\r\nSELECT\r\n\tslot, itemid, expires\r\nFROM\r\n\titems\r\nWHERE\r\n\tcharacter_id = " . $this->character_id . "\r\n\tAND\r\n\t(\r\n\t\tslot = " . $equipslot . "\r\n\t\tOR\r\n\t\tslot = " . $nameslot . "\r\n\t\tOR\r\n\t\tcashid = " . $this->cashid . "\r\n\t)");
while ($row = $q->fetch_row()) {
if ($row[0] == $equipslot) {
$this->equip = $row[1];
} elseif ($row[0] == $nameslot) {
$this->nametag = $row[1];
} else {
$this->expires = ceil($row[2] / 10000000 - 11644473600);
$this->itemid = $row[1];
}
}
}
示例7: CreateOnePlanetRecord
/**
* 2Moons
* Copyright (C) 2012 Jan Kröpke
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package 2Moons
* @author Jan Kröpke <info@2moons.cc>
* @copyright 2012 Jan Kröpke <info@2moons.cc>
* @license http://www.gnu.org/licenses/gpl.html GNU GPLv3 License
* @version 1.7.3 (2013-05-19)
* @info $Id: CreateOnePlanetRecord.php 2640 2013-03-23 19:23:26Z slaver7 $
* @link http://2moons.cc/
*/
function CreateOnePlanetRecord($Galaxy, $System, $Position, $Universe, $PlanetOwnerID, $PlanetName, $HomeWorld = false, $AuthLevel = 0, $Iron, $Gold, $Crystal, $Elyrium, $iPlanetCount)
{
global $LNG;
$CONF = Config::getAll(NULL, $Universe);
if (Config::get('max_galaxy') < $Galaxy || 1 > $Galaxy) {
throw new Exception("Access denied for CreateOnePlanetRecord.php.<br>Try to create a planet at position:" . $Galaxy . ":" . $System . ":" . $Position);
}
if (Config::get('max_system') < $System || 1 > $System) {
throw new Exception("Access denied for CreateOnePlanetRecord.php.<br>Try to create a planet at position:" . $Galaxy . ":" . $System . ":" . $Position);
}
if (Config::get('max_planets') < $Position || 1 > $Position) {
throw new Exception("Access denied for CreateOnePlanetRecord.php.<br>Try to create a planet at position:" . $Galaxy . ":" . $System . ":" . $Position);
}
if (CheckPlanetIfExist($Galaxy, $System, $Position, $Universe)) {
return false;
}
$tp = 0;
if ($iPlanetCount >= 3) {
$tp = 1;
}
$FieldFactor = Config::get('planet_factor');
require 'includes/PlanetData.php';
$Pos = ceil($Position / (Config::get('max_planets') / count($PlanetData)));
$TMax = $PlanetData[$Pos]['temp'];
$TMin = $TMax - 40;
$Fields = $PlanetData[$Pos]['fields'] * Config::get('planet_factor');
$Types = $PlanetData[$Pos]['image'];
$Name = !empty($PlanetName) ? $GLOBALS['DATABASE']->sql_escape($PlanetName) : $LNG['type_planet'][1];
$GLOBALS['DATABASE']->query("INSERT INTO " . PLANETS . " SET\n\t\t\t\tname = '" . $Name . "',\n\t\t\t\tuniverse = " . $Universe . ",\n\t\t\t\tid_owner = " . $PlanetOwnerID . ",\n\t\t\t\tgalaxy = " . $Galaxy . ",\n\t\t\t\tsystem = " . $System . ",\n\t\t\t\tplanet = " . $Position . ",\n\t\t\t\tlast_update = " . TIMESTAMP . ",\n\t\t\t\tplanet_type = '1',\n\t\t\t\tcolo_metal = " . $Iron . ",\n\t\t\t\tcolo_crystal = " . $Gold . ",\n\t\t\t\tcolo_deut = " . $Crystal . ",\n\t\t\t\tcolo_elyrium = " . $Elyrium . ",\n\t\t\t\tteleport_portal = " . $tp . ",\n\t\t\t\timage = '" . $Types . "',\n\t\t\t\tdiameter = " . floor(1000 * sqrt($Fields)) . ",\n\t\t\t\tfield_max = " . ($HomeWorld ? Config::get('initial_fields') : floor($Fields)) . ",\n\t\t\t\ttemp_min = " . $TMin . ",\n\t\t\t\ttemp_max = " . $TMax . ",\n\t\t\t\tmetal = " . Config::get('metal_start') . ",\n\t\t\t\tmetal_perhour = " . Config::get('metal_basic_income') . ",\n\t\t\t\tcrystal = " . Config::get('crystal_start') . ",\n\t\t\t\tcrystal_perhour = " . Config::get('crystal_basic_income') . ",\n\t\t\t\tdeuterium = " . Config::get('deuterium_start') . ",\n\t\t\t\tdeuterium_perhour = " . Config::get('deuterium_basic_income') . ",\n\t\t\t\telyrium = " . Config::get('deuterium_start') . ",\n\t\t\t\telyrium_perhour = " . Config::get('deuterium_basic_income') . ";");
return $GLOBALS['DATABASE']->GetInsertID();
}
示例8: run
public function run($group_id = false)
{
if (!$this->request->isAjax()) {
cmsCore::error404();
}
$grid = $this->loadDataGrid('users');
$users_model = cmsCore::getModel('users');
$users_model->setPerPage(admin::perpage);
$filter = array();
$filter_str = $this->request->get('filter');
$filter_str = cmsUser::getUPSActual('admin.grid_filter.users', $filter_str);
if ($filter_str) {
$content_model = cmsCore::getModel('content')->setTablePrefix('');
parse_str($filter_str, $filter);
$users_model->applyGridFilter($grid, $filter);
if (!empty($filter['advanced_filter'])) {
parse_str($filter['advanced_filter'], $dataset_filters);
$users_model->applyDatasetFilters($dataset_filters);
}
}
if ($group_id) {
$users_model->filterGroup($group_id);
}
$total = $users_model->getUsersCount();
$perpage = isset($filter['perpage']) ? $filter['perpage'] : admin::perpage;
$pages = ceil($total / $perpage);
$users = $users_model->getUsers();
cmsTemplate::getInstance()->renderGridRowsJSON($grid, $users, $total, $pages);
$this->halt();
}
示例9: run
public function run()
{
$page = $this->getInput('page');
$count = $this->_getPwAnnounceDs()->countAnnounce();
if (0 < $count) {
$totalPage = ceil($count / $this->pageNumber);
$page > $totalPage && ($page = $totalPage);
list($start, $limit) = Pw::page2limit($page, $this->pageNumber);
if ($page <= 0) {
$page = 1;
}
}
$announceInfo = array();
$announceInfos = $this->_getPwAnnounceDs()->getAnnounceOrderByVieworder($schoolid = '', $limit, $start);
$announceInfos = $this->_getPwAnnounceService()->formatAnnouncesUsername($announceInfos);
$openSchools = $this->_getSchoolDS()->getOpenedSchools();
$this->setOutput($openSchools, 'openSchools');
foreach ($announceInfos as $akey => &$eachInfo) {
$found = false;
foreach ($openSchools as $key => $eachSchool) {
if ($eachInfo['schoolid'] == $eachSchool['schoolid']) {
$eachInfo['schoolName'] = $eachSchool['name'];
$found = true;
break;
}
}
if ($found == false) {
$eachInfo['schoolName'] = "所有学校";
}
}
$this->setOutput($announceInfos, 'announceInfos');
$this->setOutput($count, 'count');
$this->setOutput($page, 'page');
$this->setOutput($this->pageNumber, 'perPage');
}
示例10: set
function set($entries, $page, $limit)
{
self::$entries = $entries;
self::$limit = $limit;
self::$pages = $entries > 0 ? ceil($entries / $limit) : 0;
self::$page = self::sanitize($page, self::$pages);
}
示例11: generate
/**
* @param $file_name
* @return array
* @throws ApplicationException
*/
public static function generate($file_name)
{
set_time_limit(0);
$temp_file = TempFileProvider::generate("peaks", ".raw");
$command = sprintf("%s -v quiet -i %s -ac 1 -f u8 -ar 11025 -acodec pcm_u8 %s", self::$ffmpeg_cmd, escapeshellarg($file_name), escapeshellarg($temp_file));
shell_exec($command);
if (!file_exists($temp_file)) {
throw new ApplicationException("Waveform could not be generated!");
}
$chunk_size = ceil(filesize($temp_file) / self::PEAKS_RESOLUTION);
$peaks = withOpenedFile($temp_file, "r", function ($fh) use(&$chunk_size) {
while ($data = fread($fh, $chunk_size)) {
$peak = 0;
$array = str_split($data);
foreach ($array as $item) {
$code = ord($item);
if ($code > $peak) {
$peak = $code;
}
if ($code == 255) {
break;
}
}
(yield $peak - 127);
}
});
TempFileProvider::delete($temp_file);
return $peaks;
}
示例12: execute
public function execute()
{
$this->forceSystemAuthentication();
myDbHelper::$use_alternative_con = null;
$partnerId = $this->getRequestParameter("partnerId", null);
$uiConfId = $this->getRequestParameter("uiConfId", null);
$page = $this->getRequestParameter("page", 1);
if ($partnerId !== null && $partnerId !== "") {
$pageSize = 50;
$c = new Criteria();
$c->add(widgetPeer::PARTNER_ID, $partnerId);
if ($uiConfId) {
$c->add(widgetPeer::UI_CONF_ID, $uiConfId);
}
$c->addDescendingOrderByColumn(widgetPeer::CREATED_AT);
$total = widgetPeer::doCount($c);
$lastPage = ceil($total / $pageSize);
$c->setOffset(($page - 1) * $pageSize);
$c->setLimit($pageSize);
$widgets = widgetPeer::doSelect($c);
} else {
$total = 0;
$lastPage = 0;
$widgets = array();
}
$this->uiConfId = $uiConfId;
$this->page = $page;
$this->lastPage = $lastPage;
$this->widgets = $widgets;
$this->partner = PartnerPeer::retrieveByPK($partnerId);
$this->partnerId = $partnerId;
}
示例13: pagination
function pagination($messageParPage, $table, $sscategorie)
{
/*
paginatio_array 0->Nbre d'enregistrements
paginatio_array 1->Nbre de pages
paginatio_array 2->Pages actuelle
paginatio_array 3->Première entrée
*/
$sscategorie = Utils::anti_injection($sscategorie);
$pagination_array = array();
$sqlQuery = "SELECT COUNT(*) AS total FROM " . TABLE_PREFIX . $table . " WHERE sscat_radio=" . $sscategorie;
$getTotal = Db::query($sqlQuery);
$donnees_total = Db::fetch_assoc($getTotal);
$pagination_array[0] = $donnees_total['total'];
$pagination_array[1] = ceil($pagination_array[0] / $messageParPage);
if (isset($_GET['page'])) {
$pagination_array[2] = intval($_GET['page']);
if ($pagination_array[2] > $pagination_array[1] && $pagination_array[1] > 0) {
$pagination_array[2] = $pagination_array[1];
}
} else {
$pagination_array[2] = 1;
}
$pagination_array[3] = ($pagination_array[2] - 1) * $messageParPage;
return $pagination_array;
}
示例14: getPagerInfo
function getPagerInfo()
{
global $mysqli, $table, $page, $limit, $sidx, $sord, $total_pages, $count, $start, $scol, $stext, $columnid, $compcode, $user;
if (!$sidx) {
$sidx = $columnid;
}
if (isset($_GET['Stext']) && $_GET['Scol'] == 'itemcode') {
$sql = "SELECT COUNT(*) AS count FROM {$table} \n\t\t\t\tWHERE compcode='{$compcode}' AND \n\t\t\t\t{$_GET['Scol']} LIKE '{$_GET['Stext']}%'";
} else {
if (isset($scol) && $stext != '') {
$sql = "SELECT COUNT(*) AS count FROM {$table} \n\t\t\t\tWHERE compcode='{$compcode}' AND {$_GET['Scol']} \n\t\t\t\tLIKE '%{$_GET['Stext']}%'";
} else {
$sql = "SELECT COUNT(*) AS count FROM {$table} WHERE compcode='{$compcode}'";
}
}
$result = $mysqli->query($sql);
$row = $result->fetch_assoc();
$count = $row['count'];
if ($count > 0) {
$total_pages = ceil($count / $limit);
} else {
$total_pages = 0;
}
if ($page > $total_pages && $count > 0) {
$page = $total_pages;
}
$start = $limit * $page - $limit;
}
示例15: indexAction
/**
* @Request({"filter": "array", "page":"int"})
* @Response("extension://page/views/admin/pages/index.razr")
*/
public function indexAction($filter = null, $page = 0)
{
if ($filter) {
$this['session']->set('page.filter', $filter);
} else {
$filter = $this['session']->get('page.filter', []);
}
$query = $this->pages->query();
if (isset($filter['status']) && is_numeric($filter['status'])) {
$query->where(['status' => intval($filter['status'])]);
}
if (isset($filter['search']) && strlen($filter['search'])) {
$query->where(function ($query) use($filter) {
$query->orWhere('title LIKE :search', ['search' => "%{$filter['search']}%"]);
});
}
$limit = self::PAGES_PER_PAGE;
$count = $query->count();
$total = ceil($count / $limit);
$page = max(0, min($total - 1, $page));
$query->offset($page * $limit)->limit($limit)->orderBy('title');
if ($this['request']->isXmlHttpRequest()) {
return $this['response']->json(['table' => $this['view']->render('extension://page/views/admin/pages/table.razr', ['count' => $count, 'pages' => $query->get(), 'roles' => $this->roles->findAll()]), 'total' => $total]);
}
return ['head.title' => __('Pages'), 'pages' => $query->get(), 'statuses' => Page::getStatuses(), 'filter' => $filter, 'total' => $total, 'count' => $count];
}