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 –
11 – $satir = str_replace(”
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.