本文整理汇总了PHP中CM_Util::sanitizeUtf方法的典型用法代码示例。如果您正苦于以下问题:PHP CM_Util::sanitizeUtf方法的具体用法?PHP CM_Util::sanitizeUtf怎么用?PHP CM_Util::sanitizeUtf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CM_Util
的用法示例。
在下文中一共展示了CM_Util::sanitizeUtf方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _sanitizeRecord
/**
* @param array $formattedRecord
* @return array
*/
protected function _sanitizeRecord(array $formattedRecord)
{
array_walk_recursive($formattedRecord, function (&$value, $key) {
if (is_string($value) && !mb_check_encoding($value, 'UTF-8')) {
$value = CM_Util::sanitizeUtf($value);
}
});
return $formattedRecord;
}
示例2: getQuery
public function getQuery()
{
if ($this->_bodyQuery === null) {
if ($this->_bodyEncoding == self::ENCODING_JSON) {
$body = CM_Util::sanitizeUtf($this->getBody());
if (!is_array($this->_bodyQuery = json_decode($body, true))) {
throw new CM_Exception_Invalid('Cannot extract query from body', CM_Exception::WARN, ['body' => $body]);
}
} elseif ($this->_bodyEncoding == self::ENCODING_FORM) {
parse_str($this->getBody(), $this->_bodyQuery);
} else {
$this->_bodyQuery = array();
}
}
return array_merge($this->_query, $this->_bodyQuery);
}
示例3: setUri
/**
* @param string $uri
* @throws CM_Exception_Invalid
*/
public function setUri($uri)
{
$uriWithHost = $uri;
if ('/' === substr($uriWithHost, 0, 1)) {
$uriWithHost = 'http://host' . $uri;
}
if (false === ($path = parse_url($uriWithHost, PHP_URL_PATH))) {
throw new CM_Exception_Invalid('Cannot detect path from url.', null, ['url' => $uriWithHost]);
}
if (null === $path) {
$path = '/';
}
$this->setPath($path);
if (false === ($queryString = parse_url($uriWithHost, PHP_URL_QUERY))) {
throw new CM_Exception_Invalid('Cannot detect query from url.', null, ['url' => $uriWithHost]);
}
mb_parse_str($queryString, $query);
$querySanitized = [];
foreach ($query as $key => $value) {
$key = CM_Util::sanitizeUtf($key);
if (is_array($value)) {
array_walk_recursive($value, function (&$innerValue) {
if (is_string($innerValue)) {
$innerValue = CM_Util::sanitizeUtf($innerValue);
}
});
} else {
$value = CM_Util::sanitizeUtf($value);
}
$querySanitized[$key] = $value;
}
$this->setQuery($querySanitized);
$this->setLanguageUrl(null);
$this->_uri = $uri;
}
示例4: testSanitizeUtf
public function testSanitizeUtf()
{
$this->assertSame('?.', CM_Util::sanitizeUtf(pack("H*", 'c32e')));
}
示例5: _sanitizeRecord
/**
* @param array $formattedRecord
* @return array
*/
protected function _sanitizeRecord(array $formattedRecord)
{
$nonUtfBytesList = [];
array_walk_recursive($formattedRecord, function (&$value, $key) use(&$nonUtfBytesList) {
if (is_string($value) && !mb_check_encoding($value, 'UTF-8')) {
$nonUtfBytesList[$key] = unpack('H*', $value)[1];
$value = CM_Util::sanitizeUtf($value);
}
});
if (!empty($nonUtfBytesList)) {
$formattedRecord['loggerNotifications']['sanitizedFields'] = [];
foreach ($nonUtfBytesList as $key => $nonUtfByte) {
$formattedRecord['loggerNotifications']['sanitizedFields'][$key] = $nonUtfByte;
}
}
return $formattedRecord;
}