本文整理汇总了PHP中CoreUtils::substring方法的典型用法代码示例。如果您正苦于以下问题:PHP CoreUtils::substring方法的具体用法?PHP CoreUtils::substring怎么用?PHP CoreUtils::substring使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CoreUtils
的用法示例。
在下文中一共展示了CoreUtils::substring方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _validate
/**
* Validates the input and returns an error code
*
* @return int
*/
private function _validate()
{
if (isset($this->_validator)) {
$call_params = array(&$this->_value, $this->_range);
return call_user_func_array($this->_validator, $call_params) ?? self::ERROR_NONE;
}
switch ($this->_type) {
case "bool":
if (!in_array($this->_value, array('1', '0', 'true', 'false'))) {
return self::ERROR_INVALID;
}
$this->_value = $this->_value == '1' || $this->_value == 'true';
break;
case "int":
case "float":
if (!is_numeric($this->_value)) {
return self::ERROR_INVALID;
}
$this->_value = $this->_type === 'int' ? intval($this->_value, 10) : floatval($this->_value, 10);
if (self::checkNumberRange($this->_value, $this->_range, $code)) {
return $code;
}
break;
case "text":
case "string":
if (!is_string($this->_value)) {
return self::ERROR_INVALID;
}
if (self::checkStringLength($this->_value, $this->_range, $code)) {
return $code;
}
break;
case "uuid":
if (!is_string($this->_value) || !preg_match(new RegExp('^[a-f0-9]{8}\\-[a-f0-9]{4}\\-4[a-f0-9]{3}\\-[89ab][a-f0-9]{3}\\-[a-f0-9]{12}$', 'i'), $this->_value)) {
return self::ERROR_INVALID;
}
$this->_value = strtolower($this->_value);
break;
case "username":
global $USERNAME_REGEX;
if (!is_string($this->_value) || !$USERNAME_REGEX->match($this->_value)) {
return self::ERROR_INVALID;
}
break;
case "url":
if (!is_string($this->_value)) {
return self::ERROR_INVALID;
}
global $REWRITE_REGEX;
if (stripos($this->_value, ABSPATH) === 0) {
$this->_value = CoreUtils::substring($this->_value, CoreUtils::length(ABSPATH) - 1);
}
if (!preg_match($REWRITE_REGEX, $this->_value) && !preg_match(new RegExp('^#[a-z\\-]+$'), $this->_value)) {
if (self::checkStringLength($this->_value, $this->_range, $code)) {
return $code;
}
if (!preg_match(new RegExp('^https?://[a-z\\d/.-]+/[ -~]+$', 'i'), $this->_value)) {
Response::fail('Link URL does not appear to be a valid link');
}
}
break;
case "int[]":
if (!is_string($this->_value) || !preg_match(new RegExp('^\\d{1,12}(?:,\\d{1,12})*$'), $this->_value)) {
return self::ERROR_INVALID;
}
$this->_value = explode(',', $this->_value);
break;
case "json":
try {
$this->_value = JSON::decode($this->_value);
if (empty($this->_value)) {
throw new \Exception(rtrim('Could not decode JSON; ' . json_last_error(), '; '));
}
} catch (\Exception $e) {
error_log($e->getMessage() . "\n" . $e->getTraceAsString());
return self::ERROR_INVALID;
}
break;
case "timestamp":
$this->_value = strtotime($this->_value);
if ($this->_value === false) {
return self::ERROR_INVALID;
}
if (self::checkNumberRange($this->_value, $this->_range, $code)) {
return $code;
}
break;
case "epid":
$this->_value = Episodes::parseID($this->_value);
if (empty($this->_value)) {
return self::ERROR_INVALID;
}
break;
}
return self::ERROR_NONE;
//.........这里部分代码省略.........