本文整理汇总了PHP中SimplePie_Misc::xml_encoding方法的典型用法代码示例。如果您正苦于以下问题:PHP SimplePie_Misc::xml_encoding方法的具体用法?PHP SimplePie_Misc::xml_encoding怎么用?PHP SimplePie_Misc::xml_encoding使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SimplePie_Misc
的用法示例。
在下文中一共展示了SimplePie_Misc::xml_encoding方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: init
//.........这里部分代码省略.........
}
$cache = call_user_func(array($this->cache_class, 'create'), $this->cache_location, call_user_func($this->cache_name_function, $file->url), 'spc');
}
$this->feed_url = $file->url;
} else {
$this->error = "A feed could not be found at {$this->feed_url}. A feed with an invalid mime type may fall victim to this error, or " . SIMPLEPIE_NAME . " was unable to auto-discover it.. Use force_feed() if you are certain this URL is a real feed.";
SimplePie_Misc::error($this->error, E_USER_NOTICE, __FILE__, __LINE__);
return false;
}
}
$locate = null;
}
$headers = $file->headers;
$data = $file->body;
$sniffer = new $this->content_type_sniffer_class($file);
$sniffed = $sniffer->get_type();
} else {
$data = $this->raw_data;
}
// Set up array of possible encodings
$encodings = array();
// First check to see if input has been overridden.
if ($this->input_encoding !== false) {
$encodings[] = $this->input_encoding;
}
$application_types = array('application/xml', 'application/xml-dtd', 'application/xml-external-parsed-entity');
$text_types = array('text/xml', 'text/xml-external-parsed-entity');
// RFC 3023 (only applies to sniffed content)
if (isset($sniffed)) {
if (in_array($sniffed, $application_types) || substr($sniffed, 0, 12) === 'application/' && substr($sniffed, -4) === '+xml') {
if (isset($headers['content-type']) && preg_match('/;\\x20?charset=([^;]*)/i', $headers['content-type'], $charset)) {
$encodings[] = strtoupper($charset[1]);
}
$encodings = array_merge($encodings, SimplePie_Misc::xml_encoding($data));
$encodings[] = 'UTF-8';
} elseif (in_array($sniffed, $text_types) || substr($sniffed, 0, 5) === 'text/' && substr($sniffed, -4) === '+xml') {
if (isset($headers['content-type']) && preg_match('/;\\x20?charset=([^;]*)/i', $headers['content-type'], $charset)) {
$encodings[] = $charset[1];
}
$encodings[] = 'US-ASCII';
} elseif (substr($sniffed, 0, 5) === 'text/') {
$encodings[] = 'US-ASCII';
}
}
// Fallback to XML 1.0 Appendix F.1/UTF-8/ISO-8859-1
$encodings = array_merge($encodings, SimplePie_Misc::xml_encoding($data));
$encodings[] = 'UTF-8';
$encodings[] = 'ISO-8859-1';
// There's no point in trying an encoding twice
$encodings = array_unique($encodings);
// If we want the XML, just output that with the most likely encoding and quit
if ($this->xml_dump) {
header('Content-type: text/xml; charset=' . $encodings[0]);
echo $data;
exit;
}
// Loop through each possible encoding, till we return something, or run out of possibilities
foreach ($encodings as $encoding) {
// Change the encoding to UTF-8 (as we always use UTF-8 internally)
if ($utf8_data = SimplePie_Misc::change_encoding($data, $encoding, 'UTF-8')) {
// Create new parser
$parser = new $this->parser_class();
// If it's parsed fine
if ($parser->parse($utf8_data, 'UTF-8')) {
$this->data = $parser->get_data();
if ($this->get_type() & ~SIMPLEPIE_TYPE_NONE) {
示例2: init
//.........这里部分代码省略.........
}
$cache = call_user_func(array($this->cache_class, 'create'), $this->cache_location, call_user_func($this->cache_name_function, $file->url), 'spc');
}
$this->feed_url = $file->url;
} else {
$this->error = "A feed could not be found at {$this->feed_url}";
SimplePie_Misc::error($this->error, E_USER_NOTICE, __FILE__, __LINE__);
return false;
}
}
$locate = null;
}
$headers = $file->headers;
$data = $file->body;
$sniffer = new $this->content_type_sniffer_class($file);
$sniffed = $sniffer->get_type();
} else {
$data = $this->raw_data;
}
// Set up array of possible encodings
$encodings = array();
// First check to see if input has been overridden.
if ($this->input_encoding !== false) {
$encodings[] = $this->input_encoding;
}
$application_types = array('application/xml', 'application/xml-dtd', 'application/xml-external-parsed-entity');
$text_types = array('text/xml', 'text/xml-external-parsed-entity');
// RFC 3023 (only applies to sniffed content)
if (isset($sniffed)) {
if (in_array($sniffed, $application_types) || substr($sniffed, 0, 12) === 'application/' && substr($sniffed, -4) === '+xml') {
if (isset($headers['content-type']) && preg_match('/;\\x20?charset=([^;]*)/i', $headers['content-type'], $charset)) {
$encodings[] = strtoupper($charset[1]);
}
$encodings = array_merge($encodings, SimplePie_Misc::xml_encoding($data));
$encodings[] = 'UTF-8';
} elseif (in_array($sniffed, $text_types) || substr($sniffed, 0, 5) === 'text/' && substr($sniffed, -4) === '+xml') {
if (isset($headers['content-type']) && preg_match('/;\\x20?charset=([^;]*)/i', $headers['content-type'], $charset)) {
$encodings[] = $charset[1];
}
$encodings[] = 'US-ASCII';
} elseif (substr($sniffed, 0, 5) === 'text/') {
$encodings[] = 'US-ASCII';
}
}
// Fallback to XML 1.0 Appendix F.1/UTF-8/ISO-8859-1
$encodings = array_merge($encodings, SimplePie_Misc::xml_encoding($data));
$encodings[] = 'UTF-8';
$encodings[] = 'ISO-8859-1';
// There's no point in trying an encoding twice
$encodings = array_unique($encodings);
// If we want the XML, just output that with the most likely encoding and quit
if ($this->xml_dump) {
header('Content-type: text/xml; charset=' . $encodings[0]);
echo $data;
exit;
}
// Loop through each possible encoding, till we return something, or run out of possibilities
foreach ($encodings as $encoding) {
// Change the encoding to UTF-8 (as we always use UTF-8 internally)
if ($utf8_data = SimplePie_Misc::change_encoding($data, $encoding, 'UTF-8')) {
// Create new parser
$parser =& new $this->parser_class();
// If it's parsed fine
if ($parser->parse($utf8_data, 'UTF-8')) {
$this->data = $parser->get_data();
if ($this->get_type() & ~SIMPLEPIE_TYPE_NONE) {
示例3: init
//.........这里部分代码省略.........
if ($file = $locate->find($this->autodiscovery, $this->all_discovered_feeds)) {
if ($cache) {
$this->data = array('url' => $this->feed_url, 'feed_url' => $file->url, 'build' => SIMPLEPIE_BUILD);
if (!$cache->save($this)) {
trigger_error("{$this->cache_location} is not writeable. Make sure you've set the correct relative or absolute path, and that the location is server-writable.", E_USER_WARNING);
}
$cache = call_user_func(array($this->cache_class, 'create'), $this->cache_location, call_user_func($this->cache_name_function, $file->url), 'spc');
}
$this->feed_url = $file->url;
} else {
$this->error = "A feed could not be found at {$this->feed_url}. A feed with an invalid mime type may fall victim to this error, or " . SIMPLEPIE_NAME . " was unable to auto-discover it.. Use force_feed() if you are certain this URL is a real feed.";
SimplePie_Misc::error($this->error, E_USER_NOTICE, __FILE__, __LINE__);
return false;
}
}
$locate = null;
}
$headers = $file->headers;
$data = $file->body;
$sniffer = new $this->content_type_sniffer_class($file);
$sniffed = $sniffer->get_type();
} else {
$data = $this->raw_data;
}
$this->raw_data = $data;
$encodings = array();
if ($this->input_encoding !== false) {
$encodings[] = $this->input_encoding;
}
$application_types = array('application/xml', 'application/xml-dtd', 'application/xml-external-parsed-entity');
$text_types = array('text/xml', 'text/xml-external-parsed-entity');
if (isset($sniffed)) {
if (in_array($sniffed, $application_types) || substr($sniffed, 0, 12) === 'application/' && substr($sniffed, -4) === '+xml') {
if (isset($headers['content-type']) && preg_match('/;\\x20?charset=([^;]*)/i', $headers['content-type'], $charset)) {
$encodings[] = strtoupper($charset[1]);
}
$encodings = array_merge($encodings, SimplePie_Misc::xml_encoding($data));
$encodings[] = 'UTF-8';
} elseif (in_array($sniffed, $text_types) || substr($sniffed, 0, 5) === 'text/' && substr($sniffed, -4) === '+xml') {
if (isset($headers['content-type']) && preg_match('/;\\x20?charset=([^;]*)/i', $headers['content-type'], $charset)) {
$encodings[] = $charset[1];
}
$encodings[] = 'US-ASCII';
} elseif (substr($sniffed, 0, 5) === 'text/') {
$encodings[] = 'US-ASCII';
}
}
$encodings = array_merge($encodings, SimplePie_Misc::xml_encoding($data));
$encodings[] = 'UTF-8';
$encodings[] = 'ISO-8859-1';
$encodings = array_unique($encodings);
if ($this->xml_dump) {
header('Content-type: text/xml; charset=' . $encodings[0]);
echo $data;
exit;
}
foreach ($encodings as $encoding) {
if ($utf8_data = SimplePie_Misc::change_encoding($data, $encoding, 'UTF-8')) {
$parser = new $this->parser_class();
if ($parser->parse($utf8_data, 'UTF-8')) {
$this->data = $parser->get_data();
if ($this->get_type() & ~SIMPLEPIE_TYPE_NONE) {
if (isset($headers)) {
$this->data['headers'] = $headers;
}
$this->data['build'] = SIMPLEPIE_BUILD;
if ($cache && !$cache->save($this)) {
trigger_error("{$this->cache_location} is not writeable. Make sure you've set the correct relative or absolute path, and that the location is server-writable.", E_USER_WARNING);
}
return true;
} else {
$this->error = "A feed could not be found at {$this->feed_url}. This does not appear to be a valid RSS or Atom feed.";
SimplePie_Misc::error($this->error, E_USER_NOTICE, __FILE__, __LINE__);
return false;
}
}
}
}
if (isset($parser)) {
$this->error = sprintf('This XML document is invalid, likely due to invalid characters. XML error: %s at line %d, column %d', $parser->get_error_string(), $parser->get_current_line(), $parser->get_current_column());
} else {
$this->error = 'The data could not be converted to UTF-8. You MUST have either the iconv or mbstring extension installed. Upgrading to PHP 5.x (which includes iconv) is highly recommended.';
}
SimplePie_Misc::error($this->error, E_USER_NOTICE, __FILE__, __LINE__);
return false;
} elseif (!empty($this->multifeed_url)) {
$i = 0;
$success = 0;
$this->multifeed_objects = array();
foreach ($this->multifeed_url as $url) {
$this->multifeed_objects[$i] = clone $this;
$this->multifeed_objects[$i]->set_feed_url($url);
$success |= $this->multifeed_objects[$i]->init();
$i++;
}
return (bool) $success;
} else {
return false;
}
}