本文整理匯總了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;
//.........這裏部分代碼省略.........