本文整理汇总了PHP中zbx_strlen函数的典型用法代码示例。如果您正苦于以下问题:PHP zbx_strlen函数的具体用法?PHP zbx_strlen怎么用?PHP zbx_strlen使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了zbx_strlen函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addItem
public function addItem($value, $caption = '', $selected = null, $enabled = 'yes')
{
if ($value instanceof CComboItem || $value instanceof COptGroup) {
parent::addItem($value);
} else {
$title = false;
// if caption is too long ( > 44 symbols), we add new class - 'selectShorten',
// so that the select box would not stretch
if (zbx_strlen($caption) > 44 && !$this->hasClass('selectShorten')) {
$this->setAttribute('class', $this->getAttribute('class') . ' selectShorten');
$title = true;
}
if (is_null($selected)) {
$selected = 'no';
if (is_array($this->value)) {
if (str_in_array($value, $this->value)) {
$selected = 'yes';
}
} elseif (strcmp($value, $this->value) == 0) {
$selected = 'yes';
}
} else {
$selected = 'yes';
}
$citem = new CComboItem($value, $caption, $selected, $enabled);
if ($title) {
$citem->setTitle($caption);
}
parent::addItem($citem);
}
}
示例2: add_audit_details
function add_audit_details($action, $resourcetype, $resourceid, $resourcename, $details = null)
{
if (zbx_strlen($resourcename) > 255) {
$resourcename = zbx_substr($resourcename, 0, 252) . '...';
}
$ip = !empty($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
$values = array('userid' => CWebUser::$data['userid'], 'clock' => time(), 'ip' => substr($ip, 0, 39), 'action' => $action, 'resourcetype' => $resourcetype, 'resourceid' => $resourceid, 'resourcename' => $resourcename, 'details' => $details);
try {
DB::insert('auditlog', array($values));
return true;
} catch (DBException $e) {
return false;
}
}
示例3: make_decoration
function make_decoration($haystack, $needle, $class = null)
{
$result = $haystack;
$pos = zbx_stripos($haystack, $needle);
if ($pos !== false) {
$start = zbx_substring($haystack, 0, $pos);
$end = zbx_substring($haystack, $pos + zbx_strlen($needle));
$found = zbx_substring($haystack, $pos, $pos + zbx_strlen($needle));
if (is_null($class)) {
$result = array($start, bold($found), $end);
} else {
$result = array($start, new CSpan($found, $class), $end);
}
}
return $result;
}
示例4: make_decoration
function make_decoration($haystack, $needle, $class = null)
{
$result = $haystack;
$pos = stripos($haystack, $needle);
if ($pos !== FALSE) {
$start = zbx_substring($haystack, 0, $pos);
// $middle = substr($haystack, $pos, zbx_strlen($needle));
$middle = $needle;
$end = substr($haystack, $pos + zbx_strlen($needle));
if (is_null($class)) {
$result = array($start, bold($middle), $end);
} else {
$result = array($start, new CSpan($middle, $class), $end);
}
}
return $result;
}
示例5: validate
/**
* Checks if the given string is:
* - empty
* - not too long
* - matches a certain regex
*
* @param string $value
*
* @return bool
*/
public function validate($value)
{
if (zbx_empty($value)) {
if ($this->empty) {
return true;
} else {
$this->error($this->messageEmpty);
return false;
}
}
if ($this->maxLength && zbx_strlen($value) > $this->maxLength) {
$this->error($this->messageMaxLength, $this->maxLength);
return false;
}
if ($this->regex && !zbx_empty($value) && !preg_match($this->regex, $value)) {
$this->error($this->messageRegex, $value);
return false;
}
return true;
}
示例6: checkExpression
public function checkExpression($expression)
{
$length = zbx_strlen($expression);
$symbolNum = 0;
try {
if (zbx_empty(trim($expression))) {
throw new Exception('Empty expression.');
}
// Check expr start symbol
$startSymbol = zbx_substr(trim($expression), 0, 1);
if ($startSymbol != '(' && $startSymbol != '{' && $startSymbol != '-' && !zbx_ctype_digit($startSymbol)) {
throw new Exception('Incorrect trigger expression.');
}
for ($symbolNum = 0; $symbolNum < $length; $symbolNum++) {
$symbol = zbx_substr($expression, $symbolNum, 1);
// SDI($symbol);
$this->parseOpenParts($this->previous['last']);
$this->parseCloseParts($symbol);
// SDII($this->currExpr);
if ($this->inParameter($symbol)) {
$this->setPreviousSymbol($symbol);
continue;
}
$this->checkSymbolSequence($symbol);
$this->setPreviousSymbol($symbol);
// SDII($this->symbols);
}
$symbolNum = 0;
$simpleExpression = $expression;
$this->checkBraces();
$this->checkParts($simpleExpression);
$this->checkSimpleExpression($simpleExpression);
} catch (Exception $e) {
$symbolNum = $symbolNum > 0 ? --$symbolNum : $symbolNum;
$this->errors[] = $e->getMessage();
$this->errors[] = 'Check expression part starting from " ' . zbx_substr($expression, $symbolNum) . ' "';
}
}
示例7: add_audit_ext
function add_audit_ext($action, $resourcetype, $resourceid, $resourcename, $table_name, $values_old, $values_new)
{
global $USER_DETAILS;
if (!isset($USER_DETAILS["userid"])) {
check_authorisation();
}
if ($action == AUDIT_ACTION_UPDATE) {
$values_diff = array();
foreach ($values_new as $id => $value) {
if ($values_old[$id] !== $value) {
array_push($values_diff, $id);
}
}
if (0 == count($values_diff)) {
return true;
}
}
$auditid = get_dbid('auditlog', 'auditid');
if (zbx_strlen($resourcename) > 255) {
$details = substr($resourcename, 0, 252) . '...';
}
$ip = isset($_SERVER['HTTP_X_FORWARDED_FOR']) && !empty($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
/*SDI(
'INSERT INTO auditlog (auditid,userid,clock,ip,action,resourcetype,resourceid,resourcename)'.
' values ('.$auditid.','.$USER_DETAILS['userid'].','.time().','.zbx_dbstr($ip).
','.$action.','.$resourcetype.','.$resourceid.','.zbx_dbstr($resourcename).')');*/
$result = DBexecute('INSERT INTO auditlog (auditid,userid,clock,ip,action,resourcetype,resourceid,resourcename)' . ' values (' . $auditid . ',' . $USER_DETAILS['userid'] . ',' . time() . ',' . zbx_dbstr($ip) . ',' . $action . ',' . $resourcetype . ',' . $resourceid . ',' . zbx_dbstr($resourcename) . ')');
if ($result && $action == AUDIT_ACTION_UPDATE) {
foreach ($values_diff as $id) {
$auditdetailid = get_dbid('auditlog_details', 'auditdetailid');
$result &= DBexecute('insert into auditlog_details (auditdetailid,auditid,table_name,field_name,oldvalue,newvalue)' . ' values (' . $auditdetailid . ',' . $auditid . ',' . zbx_dbstr($table_name) . ',' . zbx_dbstr($id) . ',' . zbx_dbstr($values_old[$id]) . ',' . zbx_dbstr($values_new[$id]) . ')');
}
}
if ($result) {
$result = $auditid;
}
return $result;
}
示例8: addItem
public function addItem($value, $caption = '', $selected = NULL, $enabled = 'yes')
{
// if($enabled=='no') return; /* disable item method 1 */
if (is_object($value) && zbx_strtolower(get_class($value)) == 'ccomboitem') {
parent::addItem($value);
} else {
if (zbx_strlen($caption) > 44) {
$this->setAttribute('class', 'select selectShorten');
}
if (is_null($selected)) {
$selected = 'no';
if (is_array($this->value)) {
if (str_in_array($value, $this->value)) {
$selected = 'yes';
}
} else {
if (strcmp($value, $this->value) == 0) {
$selected = 'yes';
}
}
}
parent::addItem(new CComboItem($value, $caption, $selected, $enabled));
}
}
示例9: access_deny
if (get_request('hostid') && !API::Host()->isWritable(array($_REQUEST['hostid']))) {
access_deny();
}
/*
* Actions
*/
if (isset($_REQUEST['add_expression'])) {
$_REQUEST['expression'] = $_REQUEST['expr_temp'];
$_REQUEST['expr_temp'] = '';
} elseif (isset($_REQUEST['and_expression'])) {
$_REQUEST['expr_action'] = '&';
} elseif (isset($_REQUEST['or_expression'])) {
$_REQUEST['expr_action'] = '|';
} elseif (isset($_REQUEST['replace_expression'])) {
$_REQUEST['expr_action'] = 'r';
} elseif (isset($_REQUEST['remove_expression']) && zbx_strlen($_REQUEST['remove_expression'])) {
$_REQUEST['expr_action'] = 'R';
$_REQUEST['expr_target_single'] = $_REQUEST['remove_expression'];
} elseif (isset($_REQUEST['clone']) && isset($_REQUEST['triggerid'])) {
unset($_REQUEST['triggerid']);
$_REQUEST['form'] = 'clone';
} elseif (isset($_REQUEST['save'])) {
$trigger = array('expression' => $_REQUEST['expression'], 'description' => $_REQUEST['description'], 'priority' => $_REQUEST['priority'], 'status' => $_REQUEST['status'], 'type' => $_REQUEST['type'], 'comments' => $_REQUEST['comments'], 'url' => $_REQUEST['url'], 'dependencies' => zbx_toObject(get_request('dependencies', array()), 'triggerid'));
if (get_request('triggerid')) {
// update only changed fields
$oldTrigger = API::Trigger()->get(array('triggerids' => $_REQUEST['triggerid'], 'output' => API_OUTPUT_EXTEND, 'selectDependencies' => array('triggerid')));
if (!$oldTrigger) {
access_deny();
}
$oldTrigger = reset($oldTrigger);
$oldTrigger['dependencies'] = zbx_toHash(zbx_objectValues($oldTrigger['dependencies'], 'triggerid'));
示例10: checkInput
protected function checkInput(&$hosts, $method)
{
$create = $method == 'create';
$update = $method == 'update';
$hostDBfields = $update ? array('hostid' => null) : array('host' => null);
if ($update) {
$dbHosts = $this->get(array('output' => array('hostid', 'host', 'flags'), 'hostids' => zbx_objectValues($hosts, 'hostid'), 'editable' => true, 'preservekeys' => true));
} else {
$groupids = array();
foreach ($hosts as $host) {
if (!isset($host['groups'])) {
continue;
}
$groupids = array_merge($groupids, zbx_objectValues($host['groups'], 'groupid'));
}
if ($groupids) {
$dbGroups = API::HostGroup()->get(array('output' => array('groupid'), 'groupids' => $groupids, 'editable' => true, 'preservekeys' => true));
}
}
foreach ($hosts as $host) {
// validate mandatory fields
if (!check_db_fields($hostDBfields, $host)) {
self::exception(ZBX_API_ERROR_PARAMETERS, _s('Wrong fields for host "%s".', isset($host['host']) ? $host['host'] : ''));
}
if ($update) {
$hostId = $host['hostid'];
// validate host permissions
if (!isset($dbHosts[$hostId])) {
self::exception(ZBX_API_ERROR_PARAMETERS, _('No permissions to referred object or it does not exist!'));
}
if (isset($host['groups']) && (!is_array($host['groups']) || !$host['groups'])) {
self::exception(ZBX_API_ERROR_PARAMETERS, _s('No groups for host "%s".', $dbHosts[$hostId]['host']));
}
} else {
if (!isset($host['groups']) || !is_array($host['groups']) || !$host['groups']) {
self::exception(ZBX_API_ERROR_PARAMETERS, _s('No groups for host "%s".', $host['host']));
}
foreach ($host['groups'] as $group) {
if (!isset($dbGroups[$group['groupid']])) {
self::exception(ZBX_API_ERROR_PERMISSIONS, _('No permissions to referred object or it does not exist!'));
}
}
}
}
$inventoryFields = getHostInventories();
$inventoryFields = zbx_objectValues($inventoryFields, 'db_field');
$hostNames = array();
foreach ($hosts as &$host) {
if (isset($host['inventory']) && !empty($host['inventory'])) {
if (isset($host['inventory_mode']) && $host['inventory_mode'] == HOST_INVENTORY_DISABLED) {
self::exception(ZBX_API_ERROR_PARAMETERS, _('Cannot set inventory fields for disabled inventory.'));
}
$fields = array_keys($host['inventory']);
foreach ($fields as $field) {
if (!in_array($field, $inventoryFields)) {
self::exception(ZBX_API_ERROR_PARAMETERS, _s('Incorrect inventory field "%s".', $field));
}
}
}
$updateDiscoveredValidator = new CUpdateDiscoveredValidator(array('allowed' => array('hostid', 'status', 'inventory'), 'messageAllowedField' => _('Cannot update "%1$s" for a discovered host.')));
if ($update) {
// cannot update certain fields for discovered hosts
$this->checkPartialValidator($host, $updateDiscoveredValidator, $dbHosts[$host['hostid']]);
} else {
// if visible name is not given or empty it should be set to host name
if (!isset($host['name']) || zbx_empty(trim($host['name']))) {
$host['name'] = $host['host'];
}
if (!isset($host['interfaces'])) {
self::exception(ZBX_API_ERROR_PARAMETERS, _s('No interfaces for host "%s".', $host['host']));
}
}
if (isset($host['interfaces'])) {
if (!is_array($host['interfaces']) || empty($host['interfaces'])) {
self::exception(ZBX_API_ERROR_PARAMETERS, _s('No interfaces for host "%s".', $host['host']));
}
}
if (isset($host['host'])) {
// Check if host name isn't longer than 64 chars
if (zbx_strlen($host['host']) > 64) {
self::exception(ZBX_API_ERROR_PARAMETERS, _n('Maximum host name length is %1$d characters, "%2$s" is %3$d character.', 'Maximum host name length is %1$d characters, "%2$s" is %3$d characters.', 64, $host['host'], zbx_strlen($host['host'])));
}
if (!preg_match('/^' . ZBX_PREG_HOST_FORMAT . '$/', $host['host'])) {
self::exception(ZBX_API_ERROR_PARAMETERS, _s('Incorrect characters used for host name "%s".', $host['host']));
}
if (isset($hostNames['host'][$host['host']])) {
self::exception(ZBX_API_ERROR_PARAMETERS, _s('Duplicate host. Host with the same host name "%s" already exists in data.', $host['host']));
}
$hostNames['host'][$host['host']] = $update ? $host['hostid'] : 1;
}
if (isset($host['name'])) {
if ($update) {
// if visible name is empty replace it with host name
if (zbx_empty(trim($host['name']))) {
if (!isset($host['host'])) {
self::exception(ZBX_API_ERROR_PARAMETERS, _s('Visible name cannot be empty if host name is missing.'));
}
$host['name'] = $host['host'];
}
}
//.........这里部分代码省略.........
示例11: checkValueTypes
public static function checkValueTypes($table, &$values)
{
global $DB;
$tableSchema = self::getSchema($table);
foreach ($values as $field => $value) {
if (!isset($tableSchema['fields'][$field])) {
unset($values[$field]);
continue;
}
if (is_null($values[$field])) {
if ($tableSchema['fields'][$field]['null']) {
$values[$field] = 'NULL';
} elseif (isset($tableSchema['fields'][$field]['default'])) {
$values[$field] = $tableSchema['fields'][$field]['default'];
} else {
self::exception(self::DBEXECUTE_ERROR, _s('Mandatory field "%1$s" is missing in table "%2$s".', $field, $table));
}
}
if (isset($tableSchema['fields'][$field]['ref_table'])) {
if ($tableSchema['fields'][$field]['null']) {
$values[$field] = zero2null($values[$field]);
}
}
if ($values[$field] === 'NULL') {
if (!$tableSchema['fields'][$field]['null']) {
self::exception(self::DBEXECUTE_ERROR, _s('Incorrect value "NULL" for NOT NULL field "%1$s".', $field));
}
} else {
switch ($tableSchema['fields'][$field]['type']) {
case self::FIELD_TYPE_CHAR:
$length = zbx_strlen($values[$field]);
$values[$field] = zbx_dbstr($values[$field]);
if ($length > $tableSchema['fields'][$field]['length']) {
self::exception(self::SCHEMA_ERROR, _s('Value "%1$s" is too long for field "%2$s" - %3$d characters. Allowed length is %4$d characters.', $values[$field], $field, $length, $tableSchema['fields'][$field]['length']));
}
break;
case self::FIELD_TYPE_ID:
case self::FIELD_TYPE_UINT:
if (!zbx_ctype_digit($values[$field])) {
self::exception(self::DBEXECUTE_ERROR, _s('Incorrect value "%1$s" for unsigned int field "%2$s".', $values[$field], $field));
}
$values[$field] = zbx_dbstr($values[$field]);
break;
case self::FIELD_TYPE_INT:
if (!zbx_is_int($values[$field])) {
self::exception(self::DBEXECUTE_ERROR, _s('Incorrect value "%1$s" for int field "%2$s".', $values[$field], $field));
}
$values[$field] = zbx_dbstr($values[$field]);
break;
case self::FIELD_TYPE_FLOAT:
if (!is_numeric($values[$field])) {
self::exception(self::DBEXECUTE_ERROR, _s('Incorrect value "%1$s" for float field "%2$s".', $values[$field], $field));
}
$values[$field] = zbx_dbstr($values[$field]);
break;
case self::FIELD_TYPE_TEXT:
$length = zbx_strlen($values[$field]);
$values[$field] = zbx_dbstr($values[$field]);
if ($DB['TYPE'] == ZBX_DB_DB2) {
if ($length > 2048) {
self::exception(self::SCHEMA_ERROR, _s('Value "%1$s" is too long for field "%2$s" - %3$d characters. Allowed length is 2048 characters.', $values[$field], $field, $length));
}
}
break;
}
}
}
}
示例12: checkDns
/**
* Validates the "dns" field.
*
* @throws APIException if the field is invalid.
*
* @param array $interface
*/
protected function checkDns(array $interface)
{
if (zbx_strlen($interface['dns']) > 64) {
self::exception(ZBX_API_ERROR_PARAMETERS, _n('Maximum DNS name length is %1$d characters, "%2$s" is %3$d character.', 'Maximum DNS name length is %1$d characters, "%2$s" is %3$d characters.', 64, $interface['dns'], zbx_strlen($interface['dns'])));
}
if (!empty($interface['dns']) && !preg_match('/^' . ZBX_PREG_DNS_FORMAT . '$/', $interface['dns'])) {
self::exception(ZBX_API_ERROR_PARAMETERS, _s('Incorrect interface DNS parameter "%s" provided.', $interface['dns']));
}
}
示例13: zbx_str2links
function zbx_str2links($text)
{
$result = array();
if (empty($text)) {
return $result;
}
preg_match_all('#https?://[^\\n\\t\\r ]+#u', $text, $matches, PREG_OFFSET_CAPTURE);
$start = 0;
foreach ($matches[0] as $match) {
$result[] = zbx_substr($text, $start, $match[1] - $start);
$result[] = new CLink($match[0], $match[0], null, null, true);
$start = $match[1] + zbx_strlen($match[0]);
}
$result[] = zbx_substr($text, $start, zbx_strlen($text));
return $result;
}
示例14: __construct
public function __construct($url = null)
{
$this->url = null;
$this->port = null;
$this->host = null;
$this->protocol = null;
$this->username = null;
$this->password = null;
$this->file = null;
$this->reference = null;
$this->path = null;
$this->query = null;
$this->arguments = array();
if (empty($url)) {
$this->formatArguments();
$this->url = $url = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['SCRIPT_NAME'] . '?' . $this->getQuery();
} else {
$this->url = urldecode($url);
$tmp_pos = strpos($this->url, '?');
$this->query = $tmp_pos !== false ? substr($this->url, $tmp_pos + 1) : '';
$tmp_pos = strpos($this->query, '#');
if ($tmp_pos !== false) {
$this->query = zbx_substring($this->query, 0, $tmp_pos);
}
$this->formatArguments($this->query);
}
$protocolSepIndex = strpos($this->url, '://');
if ($protocolSepIndex !== false) {
$this->protocol = strtolower(zbx_substring($this->url, 0, $protocolSepIndex));
$this->host = substr($this->url, $protocolSepIndex + 3);
$tmp_pos = strpos($this->host, '/');
if ($tmp_pos !== false) {
$this->host = zbx_substring($this->host, 0, $tmp_pos);
}
$atIndex = strpos($this->host, '@');
if ($atIndex !== false) {
$credentials = zbx_substring($this->host, 0, $atIndex);
$colonIndex = strpos(credentials, ':');
if ($colonIndex !== false) {
$this->username = zbx_substring($credentials, 0, $colonIndex);
$this->password = substr($credentials, $colonIndex);
} else {
$this->username = $credentials;
}
$this->host = substr($this->host, $atIndex + 1);
}
$host_ipv6 = strpos($this->host, ']');
if ($host_ipv6 !== false) {
if ($host_ipv6 < zbx_strlen($this->host) - 1) {
$host_ipv6++;
$host_less = substr($this->host, $host_ipv6);
$portColonIndex = strpos($host_less, ':');
if ($portColonIndex !== false) {
$this->host = zbx_substring($this->host, 0, $host_ipv6);
$this->port = substr($host_less, $portColonIndex + 1);
}
}
} else {
$portColonIndex = strpos($this->host, ':');
if ($portColonIndex !== false) {
$this->host = zbx_substring($this->host, 0, $portColonIndex);
$this->port = substr($this->host, $portColonIndex + 1);
}
}
$this->file = substr($this->url, $protocolSepIndex + 3);
$this->file = substr($this->file, strpos($this->file, '/'));
if ($this->file == $this->host) {
$this->file = '';
}
} else {
$this->file = $this->url;
}
$tmp_pos = strpos($this->file, '?');
if ($tmp_pos !== false) {
$this->file = zbx_substring($this->file, 0, $tmp_pos);
}
$refSepIndex = strpos($url, '#');
if ($refSepIndex !== false) {
$this->file = zbx_substring($this->file, 0, $refSepIndex);
$this->reference = substr($url, strpos($url, '#') + 1);
}
$this->path = $this->file;
if (zbx_strlen($this->query) > 0) {
$this->file .= '?' . $this->query;
}
if (zbx_strlen($this->reference) > 0) {
$this->file .= '#' . $this->reference;
}
if (isset($_COOKIE['zbx_sessionid'])) {
$this->setArgument('sid', substr($_COOKIE['zbx_sessionid'], 16, 16));
}
}
示例15: foreach
foreach ($expressions as $exprPart) {
if (isset($macrosData[$exprPart['expression']])) {
continue;
}
$fname = 'test_data_' . md5($exprPart['expression']);
$macrosData[$exprPart['expression']] = get_request($fname, '');
$info = get_item_function_info($exprPart['expression']);
if (!is_array($info) && isset($definedErrorPhrases[$info])) {
$allowedTesting = false;
$control = new CTextBox($fname, $macrosData[$exprPart['expression']], 30);
$control->setAttribute('disabled', 'disabled');
} else {
$octet = $info['value_type'] == 'HHMMSS';
$validation = $info['validation'];
if (substr($validation, 0, COMBO_PATTERN_LENGTH) == COMBO_PATTERN) {
$vals = explode(',', substr($validation, COMBO_PATTERN_LENGTH, zbx_strlen($validation) - COMBO_PATTERN_LENGTH - 4));
$control = new CComboBox($fname, $macrosData[$exprPart['expression']]);
foreach ($vals as $v) {
$control->addItem($v, $v);
}
} else {
$control = new CTextBox($fname, $macrosData[$exprPart['expression']], 30);
}
$fields[$fname] = array($info['type'], O_OPT, null, $validation, 'isset({test_expression})', $exprPart['expression']);
}
$data_table->addRow(new CRow(array($exprPart['expression'], is_array($info) || !isset($definedErrorPhrases[$info]) ? $info['value_type'] : new CCol($definedErrorPhrases[$info], 'disaster'), $control)));
}
}
//---------------------------------- CHECKS ------------------------------------
$fields['test_expression'] = array(T_ZBX_STR, O_OPT, P_SYS | P_ACT, null, null);
if (!check_fields($fields)) {