Пример #1
0
echo '<h1>Test libopml_parse_string</h1>';
$opml_string = <<<XML
<?xml version="1.0" encoding="UTF-8" ?>
<opml version="2.0">
\t<head>
\t</head>
\t<body>
<outline text="A" />
<outline text="Simple" />
<outline text="OPML" />
<outline text="String" />
\t</body>
</opml>
XML;
try {
    $opml_array2 = libopml_parse_string($opml_string);
    echo '<pre>';
    print_r($opml_array2);
    echo '<pre>';
} catch (LibOPML_Exception $e) {
    echo $e->getMessage();
}
echo '<h1>Test libopml_render</h1>';
try {
    $opml_string = libopml_render($opml_array1);
    echo '<pre>';
    echo htmlspecialchars($opml_string, ENT_NOQUOTES, 'UTF-8');
    echo '<pre>';
} catch (LibOPML_Exception $e) {
    echo $e->getMessage();
}
Пример #2
0
/**
 * Parse a string contained into a file as a XML string and returns the corresponding array
 *
 * @param string $filename should indicates a valid XML file
 * @param bool $strict true if "text" attribute is required, false else
 * @return array corresponding to the file content and following format described above
 * @throws LibOPML_Exception
 * @access public
 */
function libopml_parse_file($filename, $strict = true)
{
    $file_content = file_get_contents($filename);
    if ($file_content === false) {
        throw new LibOPML_Exception($filename . ' cannot be found');
    }
    return libopml_parse_string($file_content, $strict);
}
 /**
  * This method parses and imports an OPML file.
  *
  * @param string $opml_file the OPML file content.
  * @return boolean true if an error occured, false else.
  */
 private function importOpml($opml_file)
 {
     $opml_array = array();
     try {
         $opml_array = libopml_parse_string($opml_file, false);
     } catch (LibOPML_Exception $e) {
         Minz_Log::warning($e->getMessage());
         return true;
     }
     $this->catDAO->checkDefault();
     return $this->addOpmlElements($opml_array['body']);
 }