本文整理汇总了PHP中UTF8::validate方法的典型用法代码示例。如果您正苦于以下问题:PHP UTF8::validate方法的具体用法?PHP UTF8::validate怎么用?PHP UTF8::validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UTF8
的用法示例。
在下文中一共展示了UTF8::validate方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: RefererURLBeautifier_handler
function RefererURLBeautifier_handler($target, $mother)
{
$keyword = false;
if (preg_match('/\\W(q|query|k|keyword|search|stext|nlia|aqa|wd)(?:=|%3D)([^&]+)/i', $mother['url'], $matches)) {
$keyword = urldecode(rawurldecode($matches[2]));
} else {
if (strpos($mother['host'], 'images.google.') !== false && preg_match('/%3Fsearch%3D([^&]+)/i', $mother['url'], $matches)) {
$keyword = urldecode(rawurldecode($matches[1]));
} else {
if (strpos($mother['host'], 'yahoo.') !== false && preg_match('/\\Wp=([^&]+)/i', $mother['url'], $matches)) {
$keyword = urldecode(rawurldecode($matches[1]));
} else {
if (preg_match('@/search/(?:\\w+/)*([^/?]+)@i', $mother['url'], $matches)) {
$keyword = urldecode(rawurldecode($matches[1]));
}
}
}
}
if (!UTF8::validate($keyword)) {
$keyword = UTF8::correct(UTF8::bring($keyword));
}
$keyword = UTF16UrlDecode($keyword);
$url = rawurldecode(substr($mother['url'], 7));
if (!UTF8::validate($url)) {
$url = UTF8::correct(UTF8::bring($url));
}
//return '<img src="http://'.$mother['host'].'/favicon.ico" width="16" height="16" alt="Favicon" onerror="this.parentNode.removeChild(this)" style="vertical-align: middle"/> ' . (($keyword) ? '<span style="font-weight: bold; color: #594">['.htmlspecialchars($keyword).']</span> ' . UTF8::lessenAsEm($url, 65 - UTF8::lengthAsEm($keyword)) : UTF8::lessenAsEm($url, 65));
return $keyword ? '<span style="font-weight: bold; color: #594">[' . htmlspecialchars($keyword) . ']</span> ' . htmlspecialchars(UTF8::lessenAsEm($url, 70 - UTF8::lengthAsEm($keyword))) : htmlspecialchars(UTF8::lessenAsEm($url, 70));
}
示例2: open
function open($xml, $encoding = null, $nsenabled = false) {
if (!empty($encoding) && (strtolower($encoding) != 'utf-8') && !UTF8::validate($xml)) {
if (preg_match('/^<\?xml[^<]*\s+encoding=["\']?([\w-]+)["\']?/', $xml, $matches)) {
$encoding = $matches[1];
$xml = preg_replace('/^(<\?xml[^<]*\s+encoding=)["\']?[\w-]+["\']?/', '$1"utf-8"', $xml, 1);
}
if (strcasecmp($encoding, 'utf-8')) {
$xml = UTF8::bring($xml, $encoding);
if ($xml === null) {
$this->error = XML_ERROR_UNKNOWN_ENCODING;
return false;
}
}
} else {
if (substr($xml, 0, 3) == "\xEF\xBB\xBF")
$xml = substr($xml, 3);
}
$xml = str_replace('&', '&', $xml); // for parse error code 23 (&)
$this->nsenabled = $nsenabled;
$p = ($nsenabled) ? xml_parser_create_ns() : xml_parser_create();
xml_set_object($p, $this);
xml_parser_set_option($p, XML_OPTION_CASE_FOLDING, 0);
xml_set_element_handler($p, 'o', 'c');
xml_set_character_data_handler($p, 'd');
xml_set_default_handler($p, 'x');
$this->struct = array();
$this->_cursor = &$this->struct;
$this->_path = array('');
$this->_cdata = false;
if (!xml_parse($p, $xml))
return $this->_error($p);
unset($this->_cursor);
unset($this->_cdata);
if (xml_get_error_code($p) != XML_ERROR_NONE)
return $this->_error($p);
xml_parser_free($p);
return true;
}
示例3: validateArray
public static function validateArray(&$array, &$rules)
{
// Workaround for non Fancy-URL user.
$cropArray = array();
foreach ($array as $name => $value) {
$doesHaveRequest = strpos($name, '?');
if ($doesHaveRequest !== false) {
$name = substr($name, $doesHaveRequest + 1);
}
$cropArray[$name] = $value;
}
$array = $cropArray;
foreach ($rules as $key => $rule) {
if (!isset($rule[0])) {
trigger_error("Validator: The type of '{$key}' is not defined", E_USER_WARNING);
continue;
}
if (isset($array[$key]) && ($rule[0] == 'file' || strlen($array[$key]) > 0)) {
$value =& $array[$key];
if (isset($rule['min'])) {
$rule[1] = $rule['min'];
}
if (isset($rule['max'])) {
$rule[2] = $rule['max'];
}
if (isset($rule['bypass'])) {
$rule[3] = $rule['bypass'];
}
switch ($rule[0]) {
case 'any':
if (isset($rule[1]) && strlen($value) < $rule[1]) {
return false;
}
if (isset($rule[2]) && strlen($value) > $rule[2]) {
return false;
}
break;
case 'bit':
$array[$key] = self::getBit($value);
break;
case 'bool':
$array[$key] = self::getBool($value);
break;
case 'number':
if (!self::number($value, isset($rule[1]) ? $rule[1] : null, isset($rule[2]) ? $rule[2] : null, isset($rule[3]) ? $rule[3] : false)) {
return false;
}
break;
case 'int':
if (!self::isInteger($value, isset($rule[1]) ? $rule[1] : -2147483648, isset($rule[2]) ? $rule[2] : 2147483647, isset($rule[3]) ? $rule[3] : false)) {
return false;
}
break;
case 'id':
if (!self::id($value, isset($rule[1]) ? $rule[1] : 1, isset($rule[2]) ? $rule[2] : 2147483647)) {
return false;
}
break;
case 'url':
case 'string':
if (!UTF8::validate($value)) {
$value = UTF8::bring($value);
if (!UTF8::validate($value)) {
return false;
}
}
$value = $array[$key] = UTF8::correct($value);
if (isset($rule[1]) && UTF8::length($value) < $rule[1]) {
return false;
}
if (isset($rule[2]) && UTF8::length($value) > $rule[2]) {
return false;
}
break;
case 'list':
if (!self::isList($value)) {
return false;
}
break;
case 'timestamp':
if (!self::timestamp($value)) {
return false;
}
break;
case 'period':
if (!self::period($value)) {
return false;
}
break;
case 'ip':
if (!self::ip($value)) {
return false;
}
break;
case 'phone':
if (!self::phone($value)) {
return false;
}
break;
case 'domain':
//.........这里部分代码省略.........
示例4: getRefererKeywordStatistics
function getRefererKeywordStatistics()
{
$more = false;
$refereres = getRefererLogsDB();
$keywordlist = array();
$record = array();
for ($i = 0; $i < sizeof($refereres); $i++) {
$record = $refereres[$i];
if ($i == 0) {
$referredend = $record['referred'];
}
$keyword = "";
if (preg_match('/\\W(q|query|k|keyword|search|stext|nlia|aqa|wd)(?:=|%3D)([^&]+)/i', $record['url'], $matches)) {
$keyword = urldecode(rawurldecode($matches[2]));
} else {
if (strpos($record['url'], 'yahoo.') !== false && preg_match('/\\Wp=([^&]+)/i', $record['url'], $matches)) {
$keyword = urldecode(rawurldecode($matches[1]));
} else {
if (preg_match('@/search/(?:\\w+/)*([^/?]+)@i', $record['url'], $matches)) {
$keyword = urldecode(rawurldecode($matches[1]));
}
}
}
if (!UTF8::validate($keyword)) {
$keyword = UTF8::correct(UTF8::bring($keyword));
}
if (array_key_exists($keyword, $keywordlist)) {
$keywordlist[$keyword]++;
} elseif ($keyword) {
$keywordlist[$keyword] = 1;
}
}
$referredstart = array_key_exists('referred', $record) ? $record['referred'] : '';
$keywordlist = RefererKeywordArraySort($keywordlist, 'desc');
$keywordkeys = array_keys($keywordlist);
$beforekeywordvalue = '';
$rank = 0;
$keywordArray = array();
for ($i = 0; $i < sizeof($keywordlist); $i++) {
$keywordkey = $keywordkeys[$i];
$keywordvalue = $keywordlist[$keywordkey];
$keywordkey = str_replace("\"", """, $keywordkeys[$i]);
if ($keywordvalue != $beforekeywordvalue) {
$rank++;
$beforekeywordvalue = $keywordvalue;
}
array_push($keywordArray, array('keyword' => $keywordkey, 'count' => $keywordvalue, 'total' => count($keywordlist), 'rank' => $rank, 'dateStart' => Timestamp::formatDate($referredstart), 'dateEnd' => Timestamp::formatDate($referredend)));
}
return $keywordArray;
}
示例5: isUTF8
function isUTF8($str)
{
return UTF8::validate($str);
}