本文整理汇总了PHP中ctype_digit函数的典型用法代码示例。如果您正苦于以下问题:PHP ctype_digit函数的具体用法?PHP ctype_digit怎么用?PHP ctype_digit使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ctype_digit函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: denetle
function denetle($verilen, $tarif)
{
foreach ($tarif as $ne => $bilgi) {
$kosul = array_shift($bilgi);
switch ($ne) {
case 'dolu':
$hata = $kosul && empty($verilen);
break;
case 'esit':
$hata = $kosul != strlen($verilen);
break;
case 'enfazla':
$hata = strlen($verilen) > $kosul;
break;
case 'enaz':
$hata = strlen($verilen) < $kosul;
break;
case 'degeri':
$hata = $kosul != $verilen;
break;
case 'tamsayi':
$hata = $kosul && !ctype_digit($verilen);
break;
case 'ozel':
$hata = $kosul && $kosul($verilen);
break;
}
if ($hata) {
return array_shift($bilgi);
}
}
}
示例2: StdDecodePeerId
function StdDecodePeerId($id_data, $id_name)
{
$version_str = '';
for ($i = 0; $i <= strlen($id_data); $i++) {
$c = $id_data[$i];
if ($id_name == 'BitTornado' || $id_name == 'ABC') {
if ($c != '-' && ctype_digit($c)) {
$version_str .= $c . '.';
} elseif ($c != '-' && ctype_alpha($c)) {
$version_str .= ord($c) - 55 . '.';
} else {
break;
}
} elseif ($id_name == 'BitComet' || $id_name == 'BitBuddy' || $id_name == 'Lphant' || $id_name == 'BitPump' || $id_name == 'BitTorrent Plus! v2') {
if ($c != '-' && ctype_alnum($c)) {
$version_str .= $c;
if ($i == 0) {
$version_str = (int) $version_str . '.';
}
} else {
$version_str .= '.';
break;
}
} else {
if ($c != '-' && ctype_alnum($c)) {
$version_str .= $c . '.';
} else {
break;
}
}
}
$version_str = substr($version_str, 0, strlen($version_str) - 1);
return $id_name . ' ' . $version_str;
}
示例3: hasPermission
/**
* Does this role have the given permission name, id or object?
*
* @param string|int|Permission
* @return bool
*
*/
public function hasPermission($name)
{
$has = false;
if (empty($name)) {
// do nothing
} else {
if ($name instanceof Page) {
$has = $this->permissions->has($name);
} else {
if (ctype_digit("{$name}")) {
$name = (int) $name;
foreach ($this->permissions as $permission) {
if ((int) $permission->id === $name) {
$has = true;
break;
}
}
} else {
if (is_string($name)) {
foreach ($this->permissions as $permission) {
if ($permission->name === $name) {
$has = true;
break;
}
}
}
}
}
}
return $has;
}
示例4: create
/**
* Creates a feed from the given parameters.
*
* @param array feed information
* @param array items to add to the feed
* @param string define which format to use (only rss2 is supported)
* @param string define which encoding to use
* @return string
*/
public static function create($info, $items, $format = 'rss2', $encoding = 'UTF-8')
{
$info += array('title' => 'Generated Feed', 'link' => '', 'generator' => 'KohanaPHP');
$feed = '<?xml version="1.0" encoding="' . $encoding . '"?><rss version="2.0"><channel></channel></rss>';
$feed = simplexml_load_string($feed);
foreach ($info as $name => $value) {
if (($name === 'pubDate' or $name === 'lastBuildDate') and (is_int($value) or ctype_digit($value))) {
// Convert timestamps to RFC 822 formatted dates
$value = date(DATE_RFC822, $value);
} elseif (($name === 'link' or $name === 'docs') and strpos($value, '://') === FALSE) {
// Convert URIs to URLs
$value = url::site($value, 'http');
}
// Add the info to the channel
$feed->channel->addChild($name, $value);
}
foreach ($items as $item) {
// Add the item to the channel
$row = $feed->channel->addChild('item');
foreach ($item as $name => $value) {
if ($name === 'pubDate' and (is_int($value) or ctype_digit($value))) {
// Convert timestamps to RFC 822 formatted dates
$value = date(DATE_RFC822, $value);
} elseif (($name === 'link' or $name === 'guid') and strpos($value, '://') === FALSE) {
// Convert URIs to URLs
$value = url::site($value, 'http');
}
// Add the info to the row
$row->addChild($name, $value);
}
}
return $feed->asXML();
}
示例5: path
/**
* Gets a value from an array using a dot separated path.
*
* // Get the value of $array['foo']['bar']
* $value = Arr::path($array, 'foo.bar');
*
* @param array array to search
* @param string key path, dot separated
* @param mixed default value if the path is not set
* @return mixed
*/
public static function path($array, $path, $default = NULL)
{
// Split the keys by slashes
$keys = explode('.', $path);
do {
$key = array_shift($keys);
if (ctype_digit($key)) {
// Make the key an integer
$key = (int) $key;
}
if (isset($array[$key])) {
if ($keys) {
if (is_array($array[$key])) {
// Dig down into the next part of the path
$array = $array[$key];
} else {
// Unable to dig deeper
break;
}
} else {
// Found the path requested
return $array[$key];
}
} else {
// Unable to dig deeper
break;
}
} while ($keys);
// Unable to find the value requested
return $default;
}
示例6: getConfigTreeBuilder
/**
* {@inheritDoc}
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('hearsay_require_js');
$rootNode->children()->scalarNode('require_js_src')->cannotBeEmpty()->defaultValue('//cdnjs.cloudflare.com/ajax/libs/require.js/2.1.8/require.min.js')->end()->scalarNode('initialize_template')->cannotBeEmpty()->defaultValue('HearsayRequireJSBundle::initialize.html.twig')->end()->scalarNode('base_url')->defaultValue('js')->end()->scalarNode('base_dir')->isRequired()->cannotBeEmpty()->end()->arrayNode('paths')->defaultValue(array())->useAttributeAsKey('path')->normalizeKeys(false)->prototype('array')->beforeNormalization()->ifString()->then(function ($v) {
return array('location' => $v);
})->end()->children()->variableNode('location')->isRequired()->cannotBeEmpty()->validate()->always(function ($v) {
if (!is_string($v) && !is_array($v)) {
throw new InvalidTypeException();
}
$vs = !is_array($v) ? (array) $v : $v;
$er = preg_grep('~\\.js$~', $vs);
if ($er) {
throw new InvalidPathException();
}
return $v;
})->end()->end()->booleanNode('external')->cannotBeEmpty()->defaultFalse()->end()->end()->end()->end()->arrayNode('shim')->defaultValue(array())->useAttributeAsKey('name')->normalizeKeys(false)->prototype('array')->children()->arrayNode('deps')->defaultValue(array())->prototype('scalar')->end()->end()->scalarNode('exports')->end()->end()->end()->end()->arrayNode('options')->defaultValue(array())->useAttributeAsKey('name')->prototype('array')->beforeNormalization()->always(function ($v) {
return array('value' => $v);
})->end()->children()->variableNode('value')->isRequired()->end()->end()->end()->end()->arrayNode('optimizer')->children()->scalarNode('path')->isRequired()->cannotBeEmpty()->end()->booleanNode('hide_unoptimized_assets')->defaultFalse()->end()->booleanNode('declare_module_name')->defaultFalse()->end()->arrayNode('exclude')->defaultValue(array())->prototype('scalar')->end()->end()->arrayNode('modules')->defaultValue(array())->useAttributeAsKey('name')->prototype('array')->children()->scalarNode('name')->cannotBeEmpty()->end()->arrayNode('include')->defaultValue(array())->prototype('scalar')->end()->end()->arrayNode('exclude')->defaultValue(array())->prototype('scalar')->end()->end()->end()->end()->end()->arrayNode('options')->defaultValue(array())->useAttributeAsKey('name')->prototype('array')->beforeNormalization()->always(function ($v) {
return array('value' => $v);
})->end()->children()->variableNode('value')->isRequired()->end()->end()->end()->end()->scalarNode('timeout')->cannotBeEmpty()->validate()->ifTrue(function ($v) {
return !(is_int($v) || ctype_digit($v));
})->thenInvalid('Invalid number of seconds "%s"')->end()->defaultValue(60)->end()->scalarNode('almond_path')->defaultFalse()->end()->end()->end()->end();
return $treeBuilder;
}
示例7: actionGetSubjectSchedule
/**
* 日历课程接口
*/
public function actionGetSubjectSchedule()
{
if (!isset($_REQUEST['teacherId']) || !isset($_REQUEST['token']) || !isset($_REQUEST['date'])) {
$this->_return('MSG_ERR_LESS_PARAM');
}
$user_id = trim(Yii::app()->request->getParam('teacherId', null));
$token = trim(Yii::app()->request->getParam('token', null));
$date = trim(Yii::app()->request->getParam('date', null));
if (!ctype_digit($user_id)) {
$this->_return('MSG_ERR_FAIL_PARAM');
}
// 用户名不存在,返回错误
if ($user_id < 1) {
$this->_return('MSG_ERR_NO_USER');
}
// 验证日期格式合法
if (!$this->isDate($date)) {
$this->_return('MSG_ERR_FAIL_DATE_FORMAT');
}
$year = mb_substr($date, 0, 4, 'utf8');
$month = mb_substr($date, 5, 2, 'utf8');
$day = mb_substr($date, 8, 2, 'utf8');
if (empty($year) || empty($month) || empty($day)) {
$this->_return('MSG_ERR_FAIL_DATE_LESS');
}
// 验证token
if (Token::model()->verifyToken($user_id, $token)) {
// 获取日历课程
$data = Lesson::model()->getSubjectSchedule($user_id, $year, $month, $day, $date);
$this->_return('MSG_SUCCESS', $data);
} else {
$this->_return('MSG_ERR_TOKEN');
}
}
示例8: actionPostNoticeReturn
/**
* 提交消息信息
*/
public function actionPostNoticeReturn()
{
if (!isset($_REQUEST['userId']) || !isset($_REQUEST['token']) || !isset($_REQUEST['noticeId']) || !isset($_REQUEST['status'])) {
$this->_return('MSG_ERR_LESS_PARAM');
}
$user_id = trim(Yii::app()->request->getParam('userId'));
$token = trim(Yii::app()->request->getParam('token'));
$noticeId = trim(Yii::app()->request->getParam('noticeId'));
$status = trim(Yii::app()->request->getParam('status'));
if (!ctype_digit($user_id) || $user_id < 1) {
$this->_return('MSG_ERR_NO_USER');
}
if (!ctype_digit($noticeId) || $noticeId < 1 || !Notice::model()->isExistNoticeId($noticeId, $user_id)) {
$this->_return('MSG_ERR_FAIL_NOTICE');
}
if (!ctype_digit($status) || !in_array($status, array(1, 2, 3, 4))) {
$this->_return('MSG_ERR_FAIL_NOTICE_STATUS');
}
// 验证token
if (Token::model()->verifyToken($user_id, $token)) {
$data = Notice::model()->postNoticeReturn($noticeId, $status);
$this->_return('MSG_SUCCESS', $data);
} else {
$this->_return('MSG_ERR_TOKEN');
}
}
示例9: testTimestampedUID
/**
* @dataProvider provider_testTimestampedUID
*/
public function testTimestampedUID($method, $digitlen, $bits, $tbits, $hostbits)
{
$id = call_user_func(array('UIDGenerator', $method));
$this->assertEquals(true, ctype_digit($id), "UID made of digit characters");
$this->assertLessThanOrEqual($digitlen, strlen($id), "UID has the right number of digits");
$this->assertLessThanOrEqual($bits, strlen(wfBaseConvert($id, 10, 2)), "UID has the right number of bits");
$ids = array();
for ($i = 0; $i < 300; $i++) {
$ids[] = call_user_func(array('UIDGenerator', $method));
}
$lastId = array_shift($ids);
if ($hostbits) {
$lastHost = substr(wfBaseConvert($lastId, 10, 2, $bits), -$hostbits);
}
$this->assertArrayEquals(array_unique($ids), $ids, "All generated IDs are unique.");
foreach ($ids as $id) {
$id_bin = wfBaseConvert($id, 10, 2);
$lastId_bin = wfBaseConvert($lastId, 10, 2);
$this->assertGreaterThanOrEqual(substr($id_bin, 0, $tbits), substr($lastId_bin, 0, $tbits), "New ID timestamp ({$id_bin}) >= prior one ({$lastId_bin}).");
if ($hostbits) {
$this->assertEquals(substr($id_bin, 0, -$hostbits), substr($lastId_bin, 0, -$hostbits), "Host ID of ({$id_bin}) is same as prior one ({$lastId_bin}).");
}
$lastId = $id;
}
}
示例10: check_input
function check_input($details)
{
global $ALERT, $this_page;
$errors = array();
// Check each of the things the user has input.
// If there is a problem with any of them, set an entry in the $errors array.
// This will then be used to (a) indicate there were errors and (b) display
// error messages when we show the form again.
// Check email address is valid and unique.
if ($details["email"] == "") {
$errors["email"] = "Please enter your email address";
} elseif (!validate_email($details["email"])) {
// validate_email() is in includes/utilities.php
$errors["email"] = "Please enter a valid email address";
}
if (!ctype_digit($details['pid']) && $details['pid'] != '') {
$errors['pid'] = 'Please choose a valid person';
}
# if (!$details['keyword'])
# $errors['keyword'] = 'Please enter a search term';
if ((get_http_var('submitted') || get_http_var('only')) && !$details['pid'] && !$details['keyword']) {
$errors['keyword'] = 'Please choose a person and/or enter a keyword';
}
// Send the array of any errors back...
return $errors;
}
示例11: unique_key
/**
* Allows a model to be loaded by username.
*/
public function unique_key($id)
{
if (!empty($id) and is_string($id) and !ctype_digit($id)) {
return $this->columns['username'];
}
return parent::unique_key($id);
}
示例12: unique_key
/**
* Allows loading by token string.
*/
public function unique_key($id)
{
if (!empty($id) and is_string($id) and !ctype_digit($id)) {
return 'token';
}
return parent::unique_key($id);
}
示例13: column_value
protected function column_value(\ebi\Dao $dao, $name, $value)
{
if ($value === null) {
return null;
}
try {
switch ($dao->prop_anon($name, 'type')) {
case 'timestamp':
if (!ctype_digit($value)) {
$value = strtotime($value);
}
// UTCとして扱う
return date('Y-m-d H:i:s', $value - $this->timezone_offset);
case 'date':
if (!ctype_digit($value)) {
$value = strtotime($value);
}
return date('Y-m-d', $value);
case 'boolean':
return (int) $value;
}
} catch (\Exception $e) {
}
return $value;
}
示例14: __construct
public function __construct($id = NULL)
{
parent::__construct();
if ($id != NULL and (ctype_digit($id) or is_int($id))) {
// try and get a row with this ID
$data = $this->db->getwhere($this->table_name, array('id' => $id))->result(FALSE);
// try and assign the data
if (count($data) == 1 and $data = $data->current()) {
foreach ($data as $key => $value) {
$this->data[$key] = $value;
}
}
} else {
if ($id != NULL and is_string($id)) {
// try and get a row with this username/email
$data = $this->db->orwhere(array('url_name' => $id))->get($this->table_name)->result(FALSE);
// try and assign the data
if (count($data) == 1 and $data = $data->current()) {
foreach ($data as $key => $value) {
$this->data[$key] = $value;
}
}
}
}
}
示例15: resolveMessageText
public function resolveMessageText(Room $room, string $text, int $flags = self::MATCH_ANY) : Promise
{
if (preg_match('~^:\\d+\\s+(.+)~', $text, $match)) {
$text = $match[1];
}
return resolve(function () use($room, $text, $flags) {
if ($flags & self::MATCH_PERMALINKS) {
try {
$messageID = $this->resolveMessageIDFromPermalink($text);
$text = (yield $this->chatClient->getMessageText($room, $messageID));
return $flags & self::RECURSE ? $this->resolveMessageText($room, $text, $flags | self::MATCH_LITERAL_TEXT) : $text;
} catch (MessageIDNotFoundException $e) {
/* ignore, there may be other matches */
}
}
if ($flags & self::MATCH_MESSAGE_IDS && ctype_digit($text)) {
$text = (yield $this->chatClient->getMessageText($room, (int) $text));
return $flags & self::RECURSE ? $this->resolveMessageText($room, $text, $flags | self::MATCH_LITERAL_TEXT) : $text;
}
if ($flags & self::MATCH_LITERAL_TEXT) {
return $text;
}
throw new MessageFetchFailureException();
});
}