How to Create a .Txt File From .Xml With PHP or ASP

PHP supports the parsing of XML files and working with the data stored within using its XML Parser library. This library, which is supported in both PHP 4 and PHP 5, makes it fairly easy to pull data from XML files and use them as needed elsewhere, such as printing them in a nicely formatted text file.

Instructions

    • 1

      Open a text editor. Microsoft Notepad will do, but you may prefer to use a dedicated programming editor such as jEdit, Vim or Emacs.

    • 2

      Paste the following PHP code into the editor, to write the information about the XML document to a neatly formatted text file:

      <?php

      $simple = "<para><note>simple note</note></para>";

      $p = xml_parser_create();

      xml_parse_into_struct($p, $simple, $vals, $index);

      xml_parser_free($p);

      echo "Index array\n";

      print_r($index);

      echo "\nVals array\n";

      $out = print_r($vals);

      $txtFile = fopen("C:\\filename.txt", "w");

      fwrite($txtfile,$out);

      fclose($txtfile);

      ?>

    • 3

      Save the .txt file.

Related Searches:

References

Comments

You May Also Like

Related Ads

Featured