php - how to convert a parsed data into an xml format -


i want parse html content (web site) using "simple html dom parser" using code:

<!doctype html> <html> <head>     <meta http-equiv="content-type" content="text/html; charset=utf-8">     <title>parsing</title> </head> <body>     <h1>démonstration parsing </h1>     <?php     require_once 'simple_html_dom.php';     $html = new simple_html_dom();     $html->load_file('http://grafikart.fr/blog/');     // echo $html->find('img',0)->getattribute('src');     /*foreach ($html->find('img') $img) {         echo $img->src . '<br/>';     }*/  foreach ($html->find('.posts') $post){      echo 'article : '.$post->find('posts-short>p',0)->plaintext.'<br/>';      echo 'image de l\'article: '.$post->find('img',0)->src.'<br/>';           }     ?>  </body> </html> 

everything works fine, obtain parsed data xml format. have idea? thank you!

you can use simplexml.

here simple example:

<?php      $test_array = array (       'bla' => 'blub',       'foo' => 'bar',       'another_array' => array (         'stack' => 'overflow',       ),     );      $xml = new simplexmlelement('<root/>');     array_walk_recursive($test_array, array ($xml, 'addchild'));     print $xml->asxml(); ?> 

results in

*<?xml version="1.0"?> <root>   <blub>bla</blub>   <bar>foo</bar>   <overflow>stack</overflow> </root>* 

here (1,2) examples uses simple html dom simplexml.


Comments

Popular posts from this blog

android - Pass an Serializable object in AIDL -

How to provide Authorization & Authentication using Asp.net, C#? -

How to use Authorization & Authentication in Asp.net, C#? -