tux xml to text with php

There is lots of xml reading methods and classes. Some of them is too compicated. if you want to read xml with real php and simpliest way, u can use this code

php simple xml reader script

Gets only one element which you want from xml data.


1 – $file = “xml.xml”; //original xml file
2 – $handle = @fopen($file, “r”);
3 – $write = @fopen(”results.txt”, “w”); //output file
4 – $i = 0;
5 – if ($handle) {
6 – while (!feof($handle)) {
7 – $buffer = fgets($handle, 4096);
8 – $satir = $buffer;
9 – $satir = str_replace(”
10 – “,”",$satir); //your starting pattern
11 – $satir = str_replace(”
“,”",$satir); // your ending pattern
12 – if($satir != $buffer){
13 – $i++;
14 – $satir = str_replace(”\n”,”",$satir);
15 – $satir = trim($satir);
16 – $satir = $i.” – “.$satir;
17 – $satir = $satir.”\n”;
18 – fputs($write,$satir);
19 – }
20 – }
21 – fclose($handle);
22 – }
23 – ?>

u can use this with compicated xml files too. this code will get only one type of element like phrases between <phrase> </phrase> tags.
example xml data.

<element>
<url>neteyaz.com</url>
<phrase>banias - php coder</url>
<title>linux and coding blog</title>
</element>
<element>
<url>idealkilohesaplama.com</url>
<phrase>calculate your ideal weight</url>
<title>turkish web site</title>
</element>

output will be like this:

1 - banias - php coder
2 - calculate your ideal weight

enjoy.

December 2, 2009
Posted in Php — banias @ 8:57 pm

1 Comment »

  1. Pillspot.org. Canadian Health&Care.Special Internet Prices.No prescription online pharmacy.Pillspot.org. Herbal-supplements@buy.online” rel=”nofollow”>.…

    Categories: Eye Care.Pain Relief.Weight Loss.Antiviral.Antidiabetic.Skin Care.Anxiety/Sleep Aid.Mental HealthBlood Pressure/Heart.Womens Health.Vitamins/Herbal Supplements.Antidepressants.Stomach.Stop SmokingAnti-allergic/Asthma.Antibiotics.Mens H…

    Trackback by ROLAND — June 26, 2010 @ 3:55 pm

RSS feed for comments on this post. TrackBack URI

Leave a comment