本文整理汇总了PHP中libxml_clear_errors函数的典型用法代码示例。如果您正苦于以下问题:PHP libxml_clear_errors函数的具体用法?PHP libxml_clear_errors怎么用?PHP libxml_clear_errors使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了libxml_clear_errors函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: convert
/**
* Create a PHP array from the XML file
*
* @param String $xmlFile The XML file or a string containing xml to parse
*
* @return Array
*
* @throws \Propel\Common\Config\Exception\XmlParseException if parse errors occur
*/
public static function convert($xmlToParse)
{
if (!is_string($xmlToParse)) {
throw new InvalidArgumentException("XmlToArrayConverter::convert method expects an xml file to parse, or a string containing valid xml");
}
if (file_exists($xmlToParse)) {
$xmlToParse = file_get_contents($xmlToParse);
}
//Empty xml file returns empty array
if ('' === $xmlToParse) {
return array();
}
if ($xmlToParse[0] !== '<') {
throw new InvalidArgumentException('Invalid xml content');
}
$currentEntityLoader = libxml_disable_entity_loader(true);
$currentInternalErrors = libxml_use_internal_errors(true);
$xml = simplexml_load_string($xmlToParse);
$errors = libxml_get_errors();
libxml_clear_errors();
libxml_use_internal_errors($currentInternalErrors);
libxml_disable_entity_loader($currentEntityLoader);
if (count($errors) > 0) {
throw new XmlParseException($errors);
}
$conf = self::simpleXmlToArray($xml);
return $conf;
}
示例2: isValidXml
/**
* Checks to see if some XML is valid
* @param string $string as a string.
* @return boolean true if the XML appears valid.
*/
private function isValidXml($string)
{
$orig_error_setting = libxml_use_internal_errors(true);
// See security note elsewhere in this file and http://php.net/manual/en/function.libxml-disable-entity-loader.php
// Supported from 5.2.11, so allow for older versions to work as well.
if (function_exists('libxml_disable_entity_loader')) {
$original_el_setting = libxml_disable_entity_loader(false);
}
// Suppress anything PHP might moan about.
$temp = @simplexml_load_string($string);
$ok = false;
if (!$temp) {
$errors = array();
foreach (libxml_get_errors() as $libXMLError) {
$errors[] = $libXMLError->file . ' : line ' . $libXMLError->line . ', col:' . $libXMLError->column . ', message:' . $libXMLError->message;
}
libxml_clear_errors();
_debug("Error detected in XML : " . implode(',', $errors));
$ok = false;
} else {
$ok = true;
}
if (function_exists('libxml_disable_entity_loader')) {
libxml_disable_entity_loader($original_el_setting);
}
libxml_use_internal_errors($orig_error_setting);
return $ok;
}
示例3: static__escaped_fragment_
public static function static__escaped_fragment_($_escaped_fragment_)
{
\libxml_use_internal_errors(true);
$html = new \DOMDocument();
$html->loadHTML(static::default_page($_escaped_fragment_ ? $_escaped_fragment_ : true));
if ($error = \libxml_get_last_error()) {
//new \SYSTEM\LOG\ERROR('Parse Error: '.$error->message.' line:'.$error->line.' html: '.$html->saveHTML());
\libxml_clear_errors();
}
$state = \SYSTEM\PAGE\State::get(static::get_apigroup(), $_escaped_fragment_ ? $_escaped_fragment_ : static::get_default_state(), false);
foreach ($state as $row) {
$frag = new \DOMDocument();
parse_str(\parse_url($row['url'], PHP_URL_QUERY), $params);
$class = static::get_class($params);
if ($class) {
$frag->loadHTML(\SYSTEM\API\api::run('\\SYSTEM\\API\\verify', $class, static::get_params($params), static::get_apigroup(), true, false));
if ($error = \libxml_get_last_error()) {
//new \SYSTEM\LOG\ERROR('Parse Error: '.$error->message.' line:'.$error->line.' html: '.$frag->saveHTML());
\libxml_clear_errors();
}
$html->getElementById(substr($row['div'], 1))->appendChild($html->importNode($frag->documentElement, true));
//Load subpage css
foreach ($row['css'] as $css) {
$css_frag = new \DOMDocument();
$css_frag->loadHTML('<link href="' . $css . '" rel="stylesheet" type="text/css">');
$html->getElementsByTagName('head')[0]->appendChild($html->importNode($css_frag->documentElement, true));
}
}
}
echo $html->saveHTML();
new \SYSTEM\LOG\COUNTER("API was called sucessfully.");
die;
}
示例4: getScheme
/**
* Creates and returns XmlScheme object for addon
*
* @param string $addon_id Addon name
* @param string $path Path to addons
* @return AXmlScheme object
*/
public static function getScheme($addon_id, $path = '')
{
if (empty($path)) {
$path = Registry::get('config.dir.addons');
}
libxml_use_internal_errors(true);
if (!isset(self::$schemas[$addon_id])) {
$_xml = self::readXml($path . $addon_id . '/addon.xml');
if ($_xml !== FALSE) {
$versions = self::getVersionDefinition();
$version = isset($_xml['scheme']) ? (string) $_xml['scheme'] : '1.0';
self::$schemas[$addon_id] = new $versions[$version]($_xml);
} else {
$errors = libxml_get_errors();
$text_errors = array();
foreach ($errors as $error) {
$text_errors[] = self::displayXmlError($error, $_xml);
}
libxml_clear_errors();
if (!empty($text_errors)) {
fn_set_notification('E', __('xml_error'), '<br/>' . implode('<br/>', $text_errors));
}
return false;
}
}
return self::$schemas[$addon_id];
}
示例5: tempGetContent
private function tempGetContent($url)
{
$curl = new \Curl\Curl();
$curl->get($url);
$content = $curl->response;
if (empty($content)) {
return '';
}
$dom = new \DOMDocument('1.0', 'utf-8');
libxml_use_internal_errors(true);
$dom->loadHTML($content);
libxml_clear_errors();
$dom->preserveWhiteSpace = false;
// remove redundant white spaces
$body = $dom->getElementsByTagName('body');
$bodyContent = null;
if ($body && $body->length > 0) {
// remove scripts
while (($r = $dom->getElementsByTagName('script')) && $r->length) {
$r->item(0)->parentNode->removeChild($r->item(0));
}
$domBody = $body->item(0);
$bodyContent = $dom->saveXML($domBody);
//$bodyContent = $this->dom->saveHTML($this->domBody); // argument not allowed on 5.3.5 or less, see: http://www.php.net/manual/de/domdocument.savehtml.php
}
return $bodyContent;
}
示例6: decode
/**
* {@inheritdoc}
*/
public function decode($data, $format)
{
$internalErrors = libxml_use_internal_errors(true);
$disableEntities = libxml_disable_entity_loader(true);
libxml_clear_errors();
$dom = new \DOMDocument();
$dom->loadXML($data, LIBXML_NONET);
libxml_use_internal_errors($internalErrors);
libxml_disable_entity_loader($disableEntities);
foreach ($dom->childNodes as $child) {
if ($child->nodeType === XML_DOCUMENT_TYPE_NODE) {
throw new UnexpectedValueException('Document types are not allowed.');
}
}
$xml = simplexml_import_dom($dom);
if ($error = libxml_get_last_error()) {
throw new UnexpectedValueException($error->message);
}
if (!$xml->count()) {
if (!$xml->attributes()) {
return (string) $xml;
}
$data = array();
foreach ($xml->attributes() as $attrkey => $attr) {
$data['@' . $attrkey] = (string) $attr;
}
$data['#'] = (string) $xml;
return $data;
}
return $this->parseXml($xml);
}
示例7: __construct
public function __construct($strConfigSet = "")
{
libxml_use_internal_errors();
$this->objSimpleXml = simplexml_load_file(SVN2RSS_PROJECT_ROOT . "/" . SVN2RSS_CONFIG_FILE);
$arrParseErrors = libxml_get_errors();
libxml_clear_errors();
if (count($arrParseErrors) > 0) {
throw new Svn2RssException("Error parsing xml-config-file " . SVN2RSS_CONFIG_FILE . ".\nErrors:\n" . implode("\n", $arrParseErrors));
}
if ($strConfigSet == "") {
$strConfigSet = $this->getStrDefaultConfigSet();
}
if ($strConfigSet == "") {
throw new Svn2RssException("No default config-set defined in " . SVN2RSS_CONFIG_FILE);
}
//load the config-set requested
$this->strConfigSetName = $strConfigSet;
foreach ($this->objSimpleXml->configSets->configSet as $objOneConfigSet) {
$arrAttributes = $objOneConfigSet->attributes();
if ($arrAttributes->id . "" == $strConfigSet) {
$this->objCurrentConfigSetXml = $objOneConfigSet;
}
}
if ($this->objCurrentConfigSetXml == null) {
throw new Svn2RssException("Loading of config set " . $strConfigSet . " failed.");
}
}
示例8: getItems
public function getItems($max_length = 10, $force_cache_update = false)
{
if ($this->items === null) {
$this->items = array();
$xml = $this->getXML($max_length, $force_cache_update);
if ($xml != '') {
$errors = libxml_use_internal_errors(true);
try {
$document = new DOMDocument();
$document->loadXML($xml);
$xpath = new DOMXPath($document);
$this->registerXPathNamespaces($xpath);
$count = 0;
$elements = $xpath->query('//rss/channel/item');
foreach ($elements as $element) {
$count++;
if ($count > $max_length) {
break;
}
$this->items[] = new NewsFlashRSSItem($xpath, $element);
}
} catch (Exception $e) {
// ignore XML parsing exception, just return no items.
}
libxml_clear_errors();
libxml_use_internal_errors($errors);
}
}
return $this->items;
}
示例9: show_internal_errors
function show_internal_errors()
{
foreach (libxml_get_errors() as $error) {
printf("Internal: %s\n", $error->message);
}
libxml_clear_errors();
}
示例10: fromString
/**
* @param string $xml
*
* @return \DOMDocument
*/
public static function fromString($xml)
{
if (!is_string($xml) || trim($xml) === '') {
throw InvalidArgumentException::invalidType('non-empty string', $xml);
}
$entityLoader = libxml_disable_entity_loader(true);
$internalErrors = libxml_use_internal_errors(true);
libxml_clear_errors();
$domDocument = self::create();
$options = LIBXML_DTDLOAD | LIBXML_DTDATTR | LIBXML_NONET;
if (defined(LIBXML_COMPACT)) {
$options |= LIBXML_COMPACT;
}
$loaded = $domDocument->loadXML($xml, $options);
libxml_use_internal_errors($internalErrors);
libxml_disable_entity_loader($entityLoader);
if (!$loaded) {
$error = libxml_get_last_error();
libxml_clear_errors();
throw new UnparseableXmlException($error);
}
libxml_clear_errors();
foreach ($domDocument->childNodes as $child) {
if ($child->nodeType === XML_DOCUMENT_TYPE_NODE) {
throw new RuntimeException('Dangerous XML detected, DOCTYPE nodes are not allowed in the XML body');
}
}
return $domDocument;
}
示例11: __construct
public function __construct()
{
//new DOM Object
$this->redditDOM = new DOMDocument();
//get reddit source from transient or load current source
if (false === ($reddit_body = get_transient('reddit_resp'))) {
$resp = wp_remote_get('http://www.reddit.com');
$reddit_body = $resp[body];
set_transient('reddit_resp', $reddit_body, 60 * 60 * 6);
}
//HTML 5 doesn't include a DTD which confuses libxml so suppress errors
libxml_use_internal_errors(true);
$this->redditDOM->loadHTML($reddit_body);
//clear libXML errors
libxml_clear_errors();
libxml_use_internal_errors(false);
//load headlines from reddit source
$headlinestable = $this->redditDOM->getElementById("siteTable");
$this->headlines = array();
foreach ($headlinestable->childNodes as $child) {
if ($child->textContent != NULL && $child->getElementsByTagName("a")->item(1)->nodeValue != "random subreddit") {
array_push($this->headlines, new RedditHeadline($child));
}
}
usort($this->headlines, "compareHeadlines");
}
示例12: initDomDocument
/**
* Initialize DOM document
*/
public function initDomDocument()
{
if (null === ($document = $this->getDocument())) {
#require_once 'Zend/Dom/Exception.php';
throw new Zend_Dom_Exception('Cannot query; no document registered');
}
libxml_use_internal_errors(true);
$this->_domDocument = new DOMDocument();
switch ($this->getDocumentType()) {
case self::DOC_XML:
$success = $this->_domDocument->loadXML($document);
break;
case self::DOC_HTML:
case self::DOC_XHTML:
default:
$success = $this->_domDocument->loadHTML($document);
break;
}
$errors = libxml_get_errors();
if (!empty($errors)) {
$this->_documentErrors = $errors;
libxml_clear_errors();
}
libxml_use_internal_errors(false);
if (!$success) {
#require_once 'Zend/Dom/Exception.php';
throw new Zend_Dom_Exception(sprintf('Error parsing document (type == %s)', $this->getDocumentType()));
}
return $this;
}
示例13: importXML
/**
* Import the xml document from the stream into the repository
*
* @param NodeInterface $parentNode as in importXML
* @param NamespaceRegistryInterface $ns as in importXML
* @param string $uri as in importXML
* @param integer $uuidBehavior as in importXML
*
* @see PHPCR\SessionInterface::importXML
*/
public static function importXML(NodeInterface $parentNode, NamespaceRegistryInterface $ns, $uri, $uuidBehavior)
{
$use_errors = libxml_use_internal_errors(true);
libxml_clear_errors();
if (!file_exists($uri)) {
throw new \RuntimeException("File {$uri} does not exist or is not readable");
}
$xml = new FilteredXMLReader();
$xml->open($uri);
if (libxml_get_errors()) {
libxml_use_internal_errors($use_errors);
throw new InvalidSerializedDataException("Invalid xml file {$uri}");
}
$xml->read();
try {
if ('node' == $xml->localName && NamespaceRegistryInterface::NAMESPACE_SV == $xml->namespaceURI) {
// TODO: validate with DTD?
self::importSystemView($parentNode, $ns, $xml, $uuidBehavior);
} else {
self::importDocumentView($parentNode, $ns, $xml, $uuidBehavior);
}
} catch (\Exception $e) {
// restore libxml setting
libxml_use_internal_errors($use_errors);
// and rethrow exception to not hide it
throw $e;
}
libxml_use_internal_errors($use_errors);
}
示例14: sanitize
/**
* sanitize the html
*
* @since 2.2.0
*
* @param string $html target with html
* @param boolean $filter optional filter nodes
*
* @return string
*/
public function sanitize($html = null, $filter = true)
{
$doc = new DOMDocument();
$doc->loadHTML($html);
$body = $doc->getElementsByTagName('body');
/* filter nodes */
if ($filter === true) {
/* disable errors */
libxml_use_internal_errors(true);
/* process tags */
foreach ($this->_htmlTags as $tag) {
$node = $doc->getElementsByTagName($tag);
foreach ($node as $childNode) {
$childNode->parentNode->removeChild($childNode);
}
}
/* process attributes */
foreach ($body as $node) {
foreach ($node->childNodes as $childNode) {
foreach ($this->_htmlAttributes as $attribute) {
if ($childNode->hasAttribute($attribute)) {
$childNode->removeAttribute($attribute);
}
}
}
}
/* clear errors */
libxml_clear_errors();
}
$output = $doc->saveHTML($body->item(0)->childNodes->item(0));
return $output;
}
示例15: read
/**
* Convert string with xml data to php array.
*
* @throws Exception
*
* @param string $string
*
* @return array
*/
public function read($string)
{
libxml_use_internal_errors(true);
libxml_disable_entity_loader(true);
$result = simplexml_load_string($string, null, LIBXML_IMPORT_FLAGS);
if (!$result) {
$errors = libxml_get_errors();
libxml_clear_errors();
foreach ($errors as $error) {
$text = '';
switch ($error->level) {
case LIBXML_ERR_WARNING:
$text .= _s('XML file contains warning %1$s:', $error->code);
break;
case LIBXML_ERR_ERROR:
$text .= _s('XML file contains error %1$s:', $error->code);
break;
case LIBXML_ERR_FATAL:
$text .= _s('XML file contains fatal error %1$s:', $error->code);
break;
}
$text .= trim($error->message) . ' [ Line: ' . $error->line . ' | Column: ' . $error->column . ' ]';
throw new Exception($text);
}
}
$xml = new XMLReader();
$xml->xml($string);
$array = $this->xmlToArray($xml);
$xml->close();
return $array;
}