本文整理汇总了PHP中sfToolkit::isUTF8方法的典型用法代码示例。如果您正苦于以下问题:PHP sfToolkit::isUTF8方法的具体用法?PHP sfToolkit::isUTF8怎么用?PHP sfToolkit::isUTF8使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sfToolkit
的用法示例。
在下文中一共展示了sfToolkit::isUTF8方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* Executes this validator.
*
* @param mixed A parameter value
* @param error An error message reference
*
* @return bool true, if this validator executes successfully, otherwise false
*/
public function execute(&$value, &$error)
{
$decodedValue = sfToolkit::isUTF8($value) && function_exists('utf8_decode') ? utf8_decode($value) : $value;
$min = $this->getParameterHolder()->get('min');
if ($min !== null && strlen(trim($decodedValue)) < $min)
{
// too short
$error = $this->getParameterHolder()->get('min_error');
return false;
}
$max = $this->getParameterHolder()->get('max');
if ($max !== null && strlen(trim($decodedValue)) > $max)
{
// too long
$error = $this->getParameterHolder()->get('max_error');
return false;
}
$values = $this->getParameterHolder()->get('values');
if ($values !== null)
{
if ($this->getParameterHolder()->get('insensitive'))
{
$value = strtolower($value);
$found = false;
foreach ($values as $avalue)
{
if ($value == strtolower($avalue))
{
$found = true;
break;
}
}
if (!$found)
{
// can't find a match
$error = $this->getParameterHolder()->get('values_error');
return false;
}
}
else
{
if (!in_array($value, (array) $values))
{
// can't find a match
$error = $this->getParameterHolder()->get('values_error');
return false;
}
}
}
return true;
}
示例2: array
'foo_1=bar_1' => array('foo_1' => 'bar_1'),
);
foreach ($tests as $string => $attributes)
{
$t->is(sfToolkit::stringToArray($string), $attributes, '->stringToArray()');
}
// ::isUTF8()
$t->diag('::isUTF8()');
$t->is('été', true, '::isUTF8() returns true if the parameter is an UTF-8 encoded string');
$t->is(sfToolkit::isUTF8('AZERTYazerty1234-_'), true, '::isUTF8() returns true if the parameter is an UTF-8 encoded string');
$t->is(sfToolkit::isUTF8('AZERTYazerty1234-_'.chr(254)), false, '::isUTF8() returns false if the parameter is not an UTF-8 encoded string');
// check a very long string
$string = str_repeat('Here is an UTF8 string avec du français.', 1000);
$t->is(sfToolkit::isUTF8($string), true, '::isUTF8() can operate on very large strings');
// ::literalize()
$t->diag('::literalize()');
foreach (array('true', 'on', '+', 'yes') as $param)
{
$t->is(sfToolkit::literalize($param), true, sprintf('::literalize() returns true with "%s"', $param));
if (strtoupper($param) != $param)
{
$t->is(sfToolkit::literalize(strtoupper($param)), true, sprintf('::literalize() returns true with "%s"', strtoupper($param)));
}
$t->is(sfToolkit::literalize(' '.$param.' '), true, sprintf('::literalize() returns true with "%s"', ' '.$param.' '));
}
foreach (array('false', 'off', '-', 'no') as $param)
{