本文整理匯總了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;
}