Tuesday, November 16, 2010

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

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

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

$simple = "simple note";

$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);

?>

Save the .txt file.

No comments:

Post a Comment