本文整理汇总了PHP中PKPString::utf8_strip_ascii_ctrl方法的典型用法代码示例。如果您正苦于以下问题:PHP PKPString::utf8_strip_ascii_ctrl方法的具体用法?PHP PKPString::utf8_strip_ascii_ctrl怎么用?PHP PKPString::utf8_strip_ascii_ctrl使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PKPString
的用法示例。
在下文中一共展示了PKPString::utf8_strip_ascii_ctrl方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: cleanVar
/**
* Sanitize a variable.
* Removes leading and trailing whitespace, normalizes all characters to UTF-8.
* @param $var string
* @return string
*/
static function cleanVar($var)
{
// only normalize strings that are not UTF-8 already, and when the system is using UTF-8
if (Config::getVar('i18n', 'charset_normalization') == 'On' && strtolower_codesafe(Config::getVar('i18n', 'client_charset')) == 'utf-8' && !PKPString::utf8_is_valid($var)) {
$var = PKPString::utf8_normalize($var);
// convert HTML entities into valid UTF-8 characters (do not transcode)
$var = html_entity_decode($var, ENT_COMPAT, 'UTF-8');
// strip any invalid UTF-8 sequences
$var = PKPString::utf8_bad_strip($var);
$var = htmlspecialchars($var, ENT_NOQUOTES, 'UTF-8', false);
}
// strip any invalid ASCII control characters
$var = PKPString::utf8_strip_ascii_ctrl($var);
return trim($var);
}
示例2: XMLParserDOMHandler
/**
* Parse an XML file using the specified handler.
* If no handler has been specified, XMLParserDOMHandler is used by default, returning a tree structure representing the document.
* @param $file string full path to the XML file
* @param $dataCallback mixed Optional callback for data handling: function dataCallback($operation, $wrapper, $data = null)
* @return object actual return type depends on the handler
*/
function &parse($file, $dataCallback = null)
{
$parser =& $this->createParser();
if (!isset($this->handler)) {
// Use default handler for parsing
$handler = new XMLParserDOMHandler();
$this->setHandler($handler);
}
xml_set_object($parser, $this->handler);
xml_set_element_handler($parser, "startElement", "endElement");
xml_set_character_data_handler($parser, "characterData");
import('lib.pkp.classes.file.FileWrapper');
$wrapper =& FileWrapper::wrapper($file);
// Handle responses of various types
while (true) {
$newWrapper = $wrapper->open();
if (is_object($newWrapper)) {
// Follow a redirect
unset($wrapper);
$wrapper =& $newWrapper;
unset($newWrapper);
} elseif (!$newWrapper) {
// Could not open resource -- error
$returner = false;
return $returner;
} else {
// OK, we've found the end result
break;
}
}
if (!$wrapper) {
$result = false;
return $result;
}
if ($dataCallback) {
call_user_func($dataCallback, 'open', $wrapper);
}
while (!$wrapper->eof() && ($data = $wrapper->read()) !== false) {
// if the string contains non-UTF8 characters, convert it to UTF-8 for parsing
if (Config::getVar('i18n', 'charset_normalization') == 'On' && !PKPString::utf8_compliant($data)) {
$utf8_last = PKPString::substr($data, PKPString::strlen($data) - 1);
// if the string ends in a "bad" UTF-8 character, maybe it's truncated
while (!$wrapper->eof() && PKPString::utf8_bad_find($utf8_last) === 0) {
// read another chunk of data
$data .= $wrapper->read();
$utf8_last = PKPString::substr($data, PKPString::strlen($data) - 1);
}
$data = PKPString::utf8_normalize($data);
// strip any invalid UTF-8 sequences
$data = PKPString::utf8_bad_strip($data);
// convert named entities to numeric entities
$data = strtr($data, PKPString::getHTMLEntities());
}
// strip any invalid ASCII control characters
$data = PKPString::utf8_strip_ascii_ctrl($data);
if ($dataCallback) {
call_user_func($dataCallback, 'parse', $wrapper, $data);
}
if (!xml_parse($parser, $data, $wrapper->eof())) {
$this->addError(xml_error_string(xml_get_error_code($parser)));
}
}
if ($dataCallback) {
call_user_func($dataCallback, 'close', $wrapper);
}
$wrapper->close();
$result = $this->handler->getResult();
$this->destroyParser($parser);
if (isset($handler)) {
$handler->destroy();
}
return $result;
}