Optimizing aalaap at gmail dot com's php
<?php
function is_rss($feedxml) {
@$feed = simplexml_load_string($feedxml);
return ($feed->channel->item)?true:false;
}
function is_atom($feedxml) {
@$feed = new SimpleXMLElement($feedxml);
($feed->entry):true:false;
}
?>
SimpleXML
- Introdução
- Instalação/Configuração
- Constantes pré-definidas
- Exemplos
- Funções da SimpleXML
- SimpleXMLElement->addAttribute() — Adiciona um atributo à elemento SimpleXML
- SimpleXMLElement->addChild() — Adiciona um elemento filho à um nó XML
- SimpleXMLElement->asXML() — Retorna uma string XML bem formada (well-formed) baseada em um elemento SimpleXML
- SimpleXMLElement->attributes() — Identifica um atributo de um elemento
- SimpleXMLElement->children() — Encontra os nós filhos de um dado nó
- SimpleXMLElement->__construct — Creates a new SimpleXMLElement object
- SimpleXMLElement->getDocNamespaces() — Retorna um namespace declarado no documento
- SimpleXMLElement->getName() — Pega o nome de um elemento XML
- SimpleXMLElement->getNamespaces() — Retorna os namespaces utilizados no documento
- SimpleXMLElement->registerXPathNamespace() — Cria um prefixo/namespace de contexto para a próxima consulta XPath
- SimpleXMLElement->xpath() — Executa uma consulta XPath em dados XML
- simplexml_import_dom — Recebe um objeto SimpleXMLElement de um nó DOM.
- simplexml_load_file — Converte um arquivo XML em um objeto
- simplexml_load_string — Transforma uma string XML em objeto
SimpleXML
charlie at blankcanvasstudios dot com
14-Aug-2008 12:21
14-Aug-2008 12:21
aalaap at gmail dot com
30-Jun-2008 07:58
30-Jun-2008 07:58
Here are two quick and dirty functions that use SimpleXML to detect if a feed xml is RSS or ATOM:
<?php
function is_rss($feedxml) {
@$feed = new SimpleXMLElement($feedxml);
if ($feed->channel->item) {
return true;
} else {
return false;
}
}
function is_atom($feedxml) {
@$feed = new SimpleXMLElement($feedxml);
if ($feed->entry) {
return true;
} else {
return false;
}
}
?>
The functions take in the full text feed (retrieved via cURL, for example) and return a true or a false based on the result.
