本文整理汇总了PHP中in_array函数的典型用法代码示例。如果您正苦于以下问题:PHP in_array函数的具体用法?PHP in_array怎么用?PHP in_array使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了in_array函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: throwError
/**
* Throw file upload error, return true if error has been thrown, false if error has been catched
*
* @param int $number
* @param string $text
* @access public
*/
public function throwError($number, $text = false, $exit = true)
{
if ($this->_catchAllErrors || in_array($number, $this->_skipErrorsArray)) {
return false;
}
switch ($number) {
case CKFINDER_CONNECTOR_ERROR_INVALID_REQUEST:
case CKFINDER_CONNECTOR_ERROR_INVALID_NAME:
case CKFINDER_CONNECTOR_ERROR_THUMBNAILS_DISABLED:
case CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED:
header("HTTP/1.0 403 Forbidden");
header("X-CKFinder-Error: " . $number);
break;
case CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED:
header("HTTP/1.0 500 Internal Server Error");
header("X-CKFinder-Error: " . $number);
break;
default:
header("HTTP/1.0 404 Not Found");
header("X-CKFinder-Error: " . $number);
break;
}
if ($exit) {
exit;
}
}
示例2: setType
public function setType($type = self::TYPE_UNDEFINED)
{
$type = (int) $type;
if (in_array($type, array(self::TYPE_PAGE, self::TYPE_TEMPLATE, self::TYPE_UNDEFINED))) {
$this->type = $type;
}
}
示例3: PMA_sanitize
/**
* Sanitizes $message, taking into account our special codes
* for formatting.
*
* If you want to include result in element attribute, you should escape it.
*
* Examples:
*
* <p><?php echo PMA_sanitize($foo); ?></p>
*
* <a title="<?php echo PMA_sanitize($foo, true); ?>">bar</a>
*
* @uses preg_replace()
* @uses strtr()
* @param string the message
* @param boolean whether to escape html in result
*
* @return string the sanitized message
*
* @access public
*/
function PMA_sanitize($message, $escape = false, $safe = false)
{
if (!$safe) {
$message = strtr($message, array('<' => '<', '>' => '>'));
}
$replace_pairs = array('[i]' => '<em>', '[/i]' => '</em>', '[em]' => '<em>', '[/em]' => '</em>', '[b]' => '<strong>', '[/b]' => '</strong>', '[strong]' => '<strong>', '[/strong]' => '</strong>', '[tt]' => '<code>', '[/tt]' => '</code>', '[code]' => '<code>', '[/code]' => '</code>', '[kbd]' => '<kbd>', '[/kbd]' => '</kbd>', '[br]' => '<br />', '[/a]' => '</a>', '[sup]' => '<sup>', '[/sup]' => '</sup>');
$message = strtr($message, $replace_pairs);
$pattern = '/\\[a@([^"@]*)@([^]"]*)\\]/';
if (preg_match_all($pattern, $message, $founds, PREG_SET_ORDER)) {
$valid_links = array('http', './Do', './ur');
foreach ($founds as $found) {
// only http... and ./Do... allowed
if (!in_array(substr($found[1], 0, 4), $valid_links)) {
return $message;
}
// a-z and _ allowed in target
if (!empty($found[2]) && preg_match('/[^a-z_]+/i', $found[2])) {
return $message;
}
}
if (substr($found[1], 0, 4) == 'http') {
$message = preg_replace($pattern, '<a href="' . PMA_linkURL($found[1]) . '" target="\\2">', $message);
} else {
$message = preg_replace($pattern, '<a href="\\1" target="\\2">', $message);
}
}
if ($escape) {
$message = htmlspecialchars($message);
}
return $message;
}
示例4: generateRoute
/**
* Add all the routes in the router in parameter
* @param $router Router
*/
public function generateRoute(Router $router)
{
foreach ($this->classes as $class) {
$classMethods = get_class_methods($this->namespace . $class . 'Controller');
$rc = new \ReflectionClass($this->namespace . $class . 'Controller');
$parent = $rc->getParentClass();
$parent = get_class_methods($parent->name);
$className = $this->namespace . $class . 'Controller';
foreach ($classMethods as $methodName) {
if (in_array($methodName, $parent) || $methodName == 'index') {
continue;
} else {
foreach (Router::getSupportedHttpMethods() as $httpMethod) {
if (strstr($methodName, $httpMethod)) {
continue 2;
}
if (in_array($methodName . $httpMethod, $classMethods)) {
$router->add('/' . strtolower($class) . '/' . $methodName, new $className(), $methodName . $httpMethod, $httpMethod);
unset($classMethods[$methodName . $httpMethod]);
}
}
$router->add('/' . strtolower($class) . '/' . $methodName, new $className(), $methodName);
}
}
$router->add('/' . strtolower($class), new $className(), 'index');
}
}
示例5: all_for_post
public static function all_for_post($post_id, $args = array())
{
$enclosures = array();
$file_types_for_this_episode = array();
$wordpress_enclosures = get_post_meta($post_id, 'enclosure', false);
foreach ($wordpress_enclosures as $enclosure_data) {
$enclosure = Enclosure::from_enclosure_meta($enclosure_data, $post_id);
if ($enclosure->file_type && !in_array($enclosure->file_type->id, $file_types_for_this_episode)) {
$file_types_for_this_episode[] = $enclosure->file_type->id;
}
$enclosures[] = $enclosure;
}
// process podPress files
$podPress_enclosures = get_post_meta($post_id, '_podPressMedia', false);
if (is_array($podPress_enclosures) && !empty($podPress_enclosures)) {
foreach ($podPress_enclosures[0] as $file) {
$enclosure = Enclosure::from_enclosure_podPress($file, $post_id);
if (in_array($enclosure->file_type->id, $file_types_for_this_episode)) {
continue;
}
$file_types_for_this_episode[] = $enclosure->file_type->id;
$enclosures[] = $enclosure;
}
}
// if ( isset( $args['only_valid'] ) && $args['only_valid'] ) {
// foreach ( $enclosures as $enclosure ) {
// if ( $enclosure->errors ) {
// // unset( current( $enclosure ) );
// }
// }
// }
return $enclosures;
}
示例6: PrepareSettings
function PrepareSettings($arUserField)
{
$arUserField["SETTINGS"] = (is_array($arUserField["SETTINGS"]) ? $arUserField["SETTINGS"] : @unserialise($arUserField["SETTINGS"]));
$arUserField["SETTINGS"] = (is_array($arUserField["SETTINGS"]) ? $arUserField["SETTINGS"] : array());
$tmp = array("CHANNEL_ID" => intval($arUserField["SETTINGS"]["CHANNEL_ID"]));
if ($arUserField["SETTINGS"]["CHANNEL_ID"] == "add")
{
$tmp["CHANNEL_TITLE"] = trim($arUserField["SETTINGS"]["CHANNEL_TITLE"]);
$tmp["CHANNEL_SYMBOLIC_NAME"] = trim($arUserField["SETTINGS"]["CHANNEL_SYMBOLIC_NAME"]);
$tmp["CHANNEL_USE_CAPTCHA"] = ($arUserField["SETTINGS"]["CHANNEL_USE_CAPTCHA"] == "Y" ? "Y" : "N");
}
$uniqType = $arUserField["SETTINGS"]["UNIQUE"];
if (is_array($arUserField["SETTINGS"]["UNIQUE"]))
{
$uniqType = 0;
foreach ($arUserField["SETTINGS"]["UNIQUE"] as $z){
$uniqType |= $z;
}
$uniqType += 5;
}
$tmp["UNIQUE"] = $uniqType;
$tmp["UNIQUE_IP_DELAY"] = is_array($arUserField["SETTINGS"]["UNIQUE_IP_DELAY"]) ?
$arUserField["SETTINGS"]["UNIQUE_IP_DELAY"] : array();
$tmp["NOTIFY"] = (in_array($arUserField["SETTINGS"]["NOTIFY"], array("I", "Y", "N")) ?
$arUserField["SETTINGS"]["NOTIFY"] : "N");
return $tmp;
}
示例7: _validate
protected function _validate($context)
{
$config = $this->_config;
$row = $context->caller;
if (is_uploaded_file($row->file) && $config->restrict && !in_array($row->extension, $config->ignored_extensions->toArray()))
{
if ($row->isImage())
{
if (getimagesize($row->file) === false) {
$context->setError(JText::_('WARNINVALIDIMG'));
return false;
}
}
else
{
$mime = KFactory::get('com://admin/files.database.row.file')->setData(array('path' => $row->file))->mimetype;
if ($config->check_mime && $mime)
{
if (in_array($mime, $config->illegal_mimetypes->toArray()) || !in_array($mime, $config->allowed_mimetypes->toArray())) {
$context->setError(JText::_('WARNINVALIDMIME'));
return false;
}
}
elseif (!$config->authorized) {
$context->setError(JText::_('WARNNOTADMIN'));
return false;
}
}
}
}
示例8: getLinkDefsInFieldMeta
/**
* Get link definition defined in 'fields' metadata. In linkDefs can be used as value (e.g. "type": "hasChildren") and/or variables (e.g. "entityName":"{entity}"). Variables should be defined into fieldDefs (in 'entityDefs' metadata).
*
* @param string $entityName
* @param array $fieldDef
* @param array $linkFieldDefsByType
* @return array | null
*/
public function getLinkDefsInFieldMeta($entityName, $fieldDef, array $linkFieldDefsByType = null)
{
if (!isset($fieldDefsByType)) {
$fieldDefsByType = $this->getFieldDefsByType($fieldDef);
if (!isset($fieldDefsByType['linkDefs'])) {
return null;
}
$linkFieldDefsByType = $fieldDefsByType['linkDefs'];
}
foreach ($linkFieldDefsByType as $paramName => &$paramValue) {
if (preg_match('/{(.*?)}/', $paramValue, $matches)) {
if (in_array($matches[1], array_keys($fieldDef))) {
$value = $fieldDef[$matches[1]];
} else {
if (strtolower($matches[1]) == 'entity') {
$value = $entityName;
}
}
if (isset($value)) {
$paramValue = str_replace('{' . $matches[1] . '}', $value, $paramValue);
}
}
}
return $linkFieldDefsByType;
}
示例9: beforeAction
public function beforeAction($action)
{
if (!$this->owner instanceof MobileController && !in_array($this->owner->action->getId(), array_keys($this->actions()))) {
return true;
}
Yii::app()->user->loginUrl = array('/mobile/login');
Yii::app()->params->isMobileApp = true;
// fix profile linkable behavior since model was instantiated before action
if (!preg_match('/\\/mobileView$/', Yii::app()->params->profile->asa('X2LinkableBehavior')->viewRoute)) {
Yii::app()->params->profile->asa('X2LinkableBehavior')->viewRoute .= '/mobileView';
}
$this->dataUrl = $this->owner->createAbsoluteUrl($action->getId());
$this->pageId = lcfirst(preg_replace('/Controller$/', '', get_class($this->owner))) . '-' . $action->getId();
$cookie = new CHttpCookie('isMobileApp', 'true');
// create cookie
$cookie->expire = 2147483647;
// max expiration time
Yii::app()->request->cookies['isMobileApp'] = $cookie;
// save cookie
if (!$this->owner instanceof MobileController) {
$this->owner->layout = $this->pathAliasBase . 'views.layouts.main';
if ($this->owner->module) {
$this->owner->setAssetsUrl(Yii::app()->getAssetManager()->publish(Yii::getPathOfAlias($this->pathAliasBase . 'assets'), false, -1, true));
$this->owner->module->assetsUrl = $this->owner->assetsUrl;
Yii::app()->clientScript->packages = MobileModule::getPackages($this->owner->module->assetsUrl);
} else {
Yii::app()->clientScript->packages = MobileModule::getPackages($this->owner->assetsUrl);
}
}
return true;
}
示例10: fetch_all
public function fetch_all($cachenames, $lv)
{
global $_G;
$data = array();
if ($lv > 1 && !$cachenames) {
$cachenames = $_G[_config][cache_list];
}
if (defined('DEBUG')) {
$name = $this->obj->name;
if (in_array($name, array('memcache', 'baichuan'))) {
$_G['memory_debug']['get'] = array();
if (is_array($cachenames)) {
$_G['memory_debug']['get'] = $cachenames;
} else {
$_G['memory_debug']['get'][] = $key;
}
}
}
$data = $this->obj->get($cachenames);
if ($data === false || $data === NULL) {
$this->update($cachenames);
}
if (is_array($cachenames)) {
foreach ($data as $k => $v) {
if ($v === false) {
$data[$k] = $this->update($k);
}
}
}
return $data;
}
示例11: getEntityAlias
/**
* {@inheritdoc}
*/
public function getEntityAlias($entityClass)
{
if ($this->configManager->hasConfig($entityClass)) {
// check for enums
$enumCode = $this->configManager->getProvider('enum')->getConfig($entityClass)->get('code');
if ($enumCode) {
$entityAlias = $this->getEntityAliasFromConfig($entityClass);
if (null !== $entityAlias) {
return $entityAlias;
}
return $this->createEntityAlias(str_replace('_', '', $enumCode));
}
// check for dictionaries
$groups = $this->configManager->getProvider('grouping')->getConfig($entityClass)->get('groups');
if (!empty($groups) && in_array(GroupingScope::GROUP_DICTIONARY, $groups, true)) {
// delegate aliases generation to default provider
return null;
}
// exclude hidden entities
if ($this->configManager->isHiddenModel($entityClass)) {
return false;
}
// check for custom entities
if (ExtendHelper::isCustomEntity($entityClass)) {
$entityAlias = $this->getEntityAliasFromConfig($entityClass);
if (null !== $entityAlias) {
return $entityAlias;
}
return $this->createEntityAlias('Extend' . ExtendHelper::getShortClassName($entityClass));
}
}
return null;
}
示例12: moduleValidateConfiguration
/**
* Performs payment module specific configuration validation
*
* @param string &$errorMessage - error message when return result is not true
*
* @return bool - true if configuration is valid, false otherwise
*
*
*/
function moduleValidateConfiguration(&$errorMessage)
{
global $providerConf;
$commomResult = commonValidateConfiguration($errorMessage);
if (!$commomResult) {
return false;
}
if (strlen(trim($providerConf['Param_sid'])) == 0) {
$errorMessage = '\'Account number\' field is empty';
return false;
}
if (!in_array($providerConf['Param_pay_method'], array('CC', 'CK'))) {
$errorMessage = '\'Pay method\' field has incorrect value';
return false;
}
if (strlen(trim($providerConf['Param_secret_word'])) == 0) {
$errorMessage = '\'Secret word\' field is empty';
return false;
}
if (strlen(trim($providerConf['Param_secret_word'])) > 16 || strpos($providerConf['Param_secret_word'], ' ') !== false) {
$errorMessage = '\'Secret word\' field has incorrect value';
return false;
}
return true;
}
示例13: convertDateMomentToPhp
public static function convertDateMomentToPhp($format)
{
$tokens = ["M" => "n", "Mo" => "nS", "MM" => "m", "MMM" => "M", "MMMM" => "F", "D" => "j", "Do" => "jS", "DD" => "d", "DDD" => "z", "DDDo" => "zS", "DDDD" => "zS", "d" => "w", "do" => "wS", "dd" => "D", "ddd" => "D", "dddd" => "l", "e" => "w", "E" => "N", "w" => "W", "wo" => "WS", "ww" => "W", "W" => "W", "Wo" => "WS", "WW" => "W", "YY" => "y", "YYYY" => "Y", "gg" => "o", "gggg" => "o", "GG" => "o", "GGGG" => "o", "A" => "A", "a" => "a", "H" => "G", "HH" => "H", "h" => "g", "hh" => "h", "m" => "i", "mm" => "i", "s" => "s", "ss" => "s", "S" => "", "SS" => "", "SSS" => "", "z or zz" => "T", "Z" => "P", "ZZ" => "O", "X" => "U", "LT" => "g:i A", "L" => "m/d/Y", "l" => "n/j/Y", "LL" => "F jS Y", "ll" => "M j Y", "LLL" => "F js Y g:i A", "lll" => "M j Y g:i A", "LLLL" => "l, F jS Y g:i A", "llll" => "D, M j Y g:i A"];
// find all tokens from string, using regular expression
$regExp = "/(\\[[^\\[]*\\])|(\\\\)?(LT|LL?L?L?|l{1,4}|Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|W[o|W]?|YYYYY|YYYY|YY|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|mm?|ss?|SS?S?|X|zz?|ZZ?|.)/";
$matches = array();
preg_match_all($regExp, $format, $matches);
// if there is no match found then return the string as it is
// TODO: might return escaped string
if (empty($matches) || is_array($matches) === false) {
return $format;
}
// to match with extracted tokens
$momentTokens = array_keys($tokens);
$phpMatches = array();
// ----------------------------------
foreach ($matches[0] as $id => $match) {
// if there is a matching php token in token list
if (in_array($match, $momentTokens)) {
// use the php token instead
$string = $tokens[$match];
} else {
$string = $match;
}
$phpMatches[$id] = $string;
}
// join and return php specific tokens
return implode("", $phpMatches);
}
示例14: addnew
function addnew()
{
if ($_POST) {
$image = $_FILES['logo'];
$image_name = $image['name'];
$image_tmp = $image['tmp_name'];
$image_size = $image['size'];
$error = $image['error'];
$file_ext = explode('.', $image_name);
$file_ext = strtolower(end($file_ext));
$allowed_ext = array('jpg', 'jpeg', 'bmp', 'png', 'gif');
$file_on_server = '';
if (in_array($file_ext, $allowed_ext)) {
if ($error === 0) {
if ($image_size < 3145728) {
$file_on_server = uniqid() . '.' . $file_ext;
$destination = './brand_img/' . $file_on_server;
move_uploaded_file($image_tmp, $destination);
}
}
}
$values = array('name' => $this->input->post('name'), 'description' => $this->input->post('desc'), 'logo' => $file_on_server, 'is_active' => 1);
if ($this->brand->create($values)) {
$this->session->set_flashdata('message', 'New Brand added successfully');
} else {
$this->session->set_flashdata('errormessage', 'Oops! Something went wrong!!');
}
redirect(base_url() . 'brands/');
}
$this->load->helper('form');
$this->load->view('includes/header', array('title' => 'Add Brand'));
$this->load->view('brand/new_brand');
$this->load->view('includes/footer');
}
示例15: indexOp
/**
* 登录
*/
public function indexOp()
{
if (!$this->isQQLogin()) {
if (empty($_POST['username']) || empty($_POST['password']) || !in_array($_POST['client'], $this->client_type_array)) {
output_error('登录失败');
}
}
$model_member = Model('member');
$array = array();
if ($this->isQQLogin()) {
$array['member_qqopenid'] = $_SESSION['openid'];
} else {
$array['member_name'] = $_POST['username'];
$array['member_passwd'] = md5($_POST['password']);
}
$member_info = $model_member->getMemberInfo($array);
if (!empty($member_info)) {
$token = $this->_get_token($member_info['member_id'], $member_info['member_name'], $_POST['client']);
if ($token) {
if ($this->isQQLogin()) {
setNc2Cookie('username', $member_info['member_name']);
setNc2Cookie('key', $token);
header("location:" . WAP_SITE_URL . '/tmpl/member/member.html?act=member');
} else {
output_data(array('username' => $member_info['member_name'], 'key' => $token));
}
} else {
output_error('登录失败');
}
} else {
output_error('用户名密码错误');
}
}