本文整理汇总了PHP中utf8::sanitize方法的典型用法代码示例。如果您正苦于以下问题:PHP utf8::sanitize方法的具体用法?PHP utf8::sanitize怎么用?PHP utf8::sanitize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类utf8
的用法示例。
在下文中一共展示了utf8::sanitize方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: applyMacros
/**
* Deals with the [macro parameters] substitutions
*
* See the macroList plugin for details
*
* @param string $text
* @return string
*/
function applyMacros($text)
{
$content_macros = getMacros();
preg_match_all('/\\[(\\w+)(.*?)\\]/i', $text, $instances);
foreach ($instances[0] as $instance => $macro_instance) {
$macroname = strtoupper($instances[1][$instance]);
if (array_key_exists($macroname, $content_macros)) {
$macro = $content_macros[$macroname];
$p = $instances[2][$instance];
$data = NULL;
$class = $macro['class'];
if ($p) {
$p = trim(utf8::sanitize(str_replace(" ", ' ', strip_tags($p))));
// remove hard spaces and invalid characters
$p = preg_replace("~\\s+=\\s+(?=(?:[^\"]*+\"[^\"]*+\")*+[^\"]*+\$)~", "=", $p);
// deblank assignment operator
preg_match_all("~'[^'\"]++'|\"[^\"]++\"|[^\\s]++~", $p, $l);
// parse the parameter list
$parms = array();
$k = 0;
foreach ($l[0] as $s) {
if ($s != ',') {
$parms[$k++] = trim($s, '\'"');
// remove any quote marks
}
}
} else {
$parms = array();
}
$parameters = array();
if (!empty($macro['params'])) {
$err = false;
foreach ($macro['params'] as $key => $type) {
$data = false;
if (array_key_exists($key, $parms)) {
switch (trim($type, '*')) {
case 'int':
if (is_numeric($parms[$key])) {
$parameters[] = (int) $parms[$key];
} else {
$data = '<span class="error">' . sprintf(gettext('<em>[%1$s]</em> parameter %2$d should be a number.'), trim($macro_instance, '[]'), $key + 1) . '</span>';
$class = 'error';
}
break;
case 'string':
if (is_string($parms[$key])) {
$parameters[] = $parms[$key];
} else {
$data = '<span class="error">' . sprintf(gettext('<em>[%1$s]</em> parameter %2$d should be a string.'), trim($macro_instance, '[]'), $key + 1) . '</span>';
$class = 'error';
}
break;
case 'bool':
switch (strtolower($parms[$key])) {
case "true":
$parameters[] = true;
break;
case "false":
$parameters[] = false;
break;
default:
$data = '<span class="error">' . sprintf(gettext('<em>[%1$s]</em> parameter %2$d should be <code>true</code> or <code>false</code>.'), trim($macro_instance, '[]'), $key + 1) . '</span>';
$class = 'error';
break;
}
break;
case 'array':
$l = array_slice($parms, $key);
$parms = array();
foreach ($l as $key => $p) {
$x = explode('=', $p);
if (count($x) == 2) {
$parms[$x[0]] = $x[1];
} else {
$parms[$key] = $x[0];
}
}
$parameters[] = $parms;
break;
default:
$data = '<span class="error">' . sprintf(gettext('<em>[%1$s]</em> parameter %2$d is incorrectly defined.'), trim($macro_instance, '[]'), $key + 1) . '</span>';
$class = 'error';
break;
}
} else {
if (strpos($type, '*') === false) {
$data = '<span class="error">' . sprintf(gettext('<em>[%1$s]</em> parameter %2$d is missing.'), trim($macro_instance, '[]'), $key + 1) . '</span>';
$class = 'error';
}
break;
}
}
//.........这里部分代码省略.........