# Help Needed

**URL:** <https://forum.kirupa.com/t/help-needed/266447>\
**Category:** Uncategorized\
**Created:** [July 20, 2008, 8:55pm UTC](https://forum.kirupa.com/t/help-needed/266447 "2008-07-20T20:55:50Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![enverge](https://avatars.discourse-cdn.com/v4/letter/e/5e9695/32.png) [@enverge](https://forum.kirupa.com/u/enverge)\
**Post date:** [July 20, 2008, 8:55pm UTC](https://forum.kirupa.com/t/help-needed/266447/1 "2008-07-20T20:55:50Z")

</div>

**[FONT=Arial][SIZE=3][COLOR=#003366]I have just used the news editor from:[/COLOR][/SIZE][/FONT]**  
**[SIZE=3][COLOR=#003366][/COLOR][/SIZE]**  
**[SIZE=3][COLOR=#003366]Introduction[/COLOR][/SIZE]**[SIZE=3][FONT=Verdana][COLOR=#003366] to XML in Flash  
[/COLOR][/FONT][FONT=Verdana][COLOR=#666666] by senocular[/COLOR][/FONT][/SIZE][FONT=Verdana][COLOR=#003366]

[/COLOR][/FONT]**[SIZE=3]Example: News Editor[/SIZE]**  
**[SIZE=3][/SIZE]**  
**[SIZE=3]I am having problems parsing the xml in php, I am ripping my hair out, can anyone help? Nothing shows![/SIZE]**  
**[SIZE=3][/SIZE]**  
**[SIZE=3]Parser code (this is a generic one I use for all my feed, I just tweak it)[/SIZE]**

\<?php  
function xml2array($data) {  
$p = xml\_parser\_create();  
xml\_parser\_set\_option($p, XML\_OPTION\_SKIP\_WHITE, 1);  
xml\_parse\_into\_struct($p, $data, $vals, $index);  
xml\_parser\_free($p);  
$tree = array();  
$i = 0;  
//array\_push($tree, array(‘tag’ =\> $vals[$i][‘tag’], ‘attributes’=\> $vals[$i][‘attributes’], ‘children’ =\> ));  
$tree = GetChildren($vals, $i);  
return $tree;  
}  
function GetChildren($vals, &$i) {  
$children = array();  
$j = 0;  
if (isset($vals[$i][‘value’])) array\_push($children, $vals[$i][‘value’]);

$prevtag = “”;  
while (++$i \< count($vals)) // so pra nao botar while true 😉  
{  
switch ($vals[$i][‘type’])  
{  
case ‘cdata’:  
array\_push($children, $vals[$i][‘value’]);  
break;  
case ‘complete’:  
$children[strtolower($vals[$i][‘tag’]) ] = ( (isset($vals[$i][‘value’])) ? $vals[$i][‘value’] : “”);  
break;  
case ‘open’:

```
       //restartindex on unique tag-name
       $j++;
       if ($prevtag &lt;&gt; $vals[$i]['tag']) {
               $j = 0;   
               $prevtag = $vals[$i]['tag'];
       }                             
       $children[strtolower($vals[$i]['tag']) ][$j] = GetChildren($vals,$i);
       break;
     case 'close':         
       return $children;
 }

```

}  
}  
function read\_page($url) {  
$content = “”;  
$dataFile = fopen( $url , “r” ) ;  
//html convertor  
$source = array("\222","\226", “\223”, “\224”);  
$target = array("’","-",""", “”");  
if ( $dataFile ) {  
while (!feof($dataFile)) {  
$buffer = fread($dataFile, 4096);  
$content .= str\_replace($source, $target, $buffer);  
//$content .= addcslashes($buffer, “\177…\377”);  
}  
fclose($dataFile);  
} else {  
die( “fopen failed for $url” ) ;  
}  
return $content;  
}

$feeduri = “[admin/readwrite/news.xml](http://www.randomharvestcharters.co.uk/web/admin/news/news.xml)”;  
$xml = read\_page($feeduri);  
$data = xml2array($xml);

//print\_r($data);  
$media = $data[‘news’][0];  
?\>  
\<?php  
$showlim = ((isset($\_GET[‘limit’])) ? $\_GET[‘limit’] : 10);  
for($i = 0; $i \< $showlim; $i++) {  
$entry = $media[‘entry’][$i]; // as $entry) {  
?\>  
\<div id=“title”\>  
\<? echo $entry[‘title’]; ?\> \</div\>  
\<div id=“desc”\>  
\<? echo $entry[‘body’]; ?\>\</div\>  
\<hr /\>  
\<?  
}  
?\>

[SIZE=3]This is the xml from the browser:[/SIZE]  
[SIZE=3][/SIZE]  
\<news\>  
\<entry\>  
\<title\>No 2\</title\>  
\<body\>this is number 2\</body\>  
\</entry\>  
\<entry\>  
\<title\>This is 1\</title\>  
\<body\>some text for 1\</body\>  
\</entry\>  
\</news\>

much appreciated if someone can

many thanks  
Brian
