本文整理汇总了PHP中Hubzero\Utility\String::clean方法的典型用法代码示例。如果您正苦于以下问题:PHP String::clean方法的具体用法?PHP String::clean怎么用?PHP String::clean使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Hubzero\Utility\String
的用法示例。
在下文中一共展示了String::clean方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: filterField
/**
* Method to apply an input filter to a value based on field data.
*
* @param string $element The XML element object representation of the form field.
* @param mixed $value The value to filter for the field.
* @return mixed The filtered value.
*/
protected function filterField($element, $value)
{
// Make sure there is a valid SimpleXMLElement.
if (!$element instanceof SimpleXMLElement) {
return false;
}
// Get the field filter type.
$filter = (string) $element['filter'];
// Process the input value based on the filter.
$return = null;
switch (strtoupper($filter)) {
// Access Control Rules.
case 'RULES':
$return = array();
foreach ((array) $value as $action => $ids) {
// Build the rules array.
$return[$action] = array();
foreach ($ids as $id => $p) {
if ($p !== '') {
$return[$action][$id] = $p == '1' || $p == 'true' ? true : false;
}
}
}
break;
// Do nothing, thus leaving the return value as null.
// Do nothing, thus leaving the return value as null.
case 'UNSET':
break;
// No Filter.
// No Filter.
case 'RAW':
$return = $value;
break;
// Filter the input as an array of integers.
// Filter the input as an array of integers.
case 'INT_ARRAY':
// Make sure the input is an array.
if (is_object($value)) {
$value = get_object_vars($value);
}
$value = is_array($value) ? $value : array($value);
Arr::toInteger($value);
$return = $value;
break;
// Filter safe HTML.
// Filter safe HTML.
case 'SAFEHTML':
$return = String::clean($value, 'string');
break;
// Convert a date to UTC based on the server timezone offset.
// Convert a date to UTC based on the server timezone offset.
case 'SERVER_UTC':
if (intval($value) > 0) {
// Get the server timezone setting.
$offset = App::get('config')->get('offset');
// Return an SQL formatted datetime string in UTC.
$return = with(new Date($value, $offset))->toSql();
} else {
$return = '';
}
break;
// Convert a date to UTC based on the user timezone offset.
// Convert a date to UTC based on the user timezone offset.
case 'USER_UTC':
if (intval($value) > 0) {
// Get the user timezone setting defaulting to the server timezone setting.
$offset = App::get('user')->getParam('timezone', App::get('config')->get('offset'));
// Return a MySQL formatted datetime string in UTC.
$return = with(new Date($value, $offset))->toSql();
} else {
$return = '';
}
break;
// Ensures a protocol is present in the saved field. Only use when
// the only permitted protocols requre '://'. See FormRuleUrl for list of these.
// Ensures a protocol is present in the saved field. Only use when
// the only permitted protocols requre '://'. See FormRuleUrl for list of these.
case 'URL':
if (empty($value)) {
return false;
}
$value = String::clean($value);
$value = trim($value);
// <>" are never valid in a uri see http://www.ietf.org/rfc/rfc1738.txt.
$value = str_replace(array('<', '>', '"'), '', $value);
// Check for a protocol
$protocol = parse_url($value, PHP_URL_SCHEME);
// If there is no protocol and the relative option is not specified,
// we assume that it is an external URL and prepend http://.
if ($element['type'] == 'url' && !$protocol && !$element['relative'] || !$element['type'] == 'url' && !$protocol) {
$protocol = 'http';
// If it looks like an internal link, then add the root.
if (substr($value, 0, 9) == 'index.php') {
//.........这里部分代码省略.........