You are here: So lost, xml, php, arrays help pls! « All PHP « IT news, forums, messages
So lost, xml, php, arrays help pls!

Posted by silvrique@gmail.com on 06/14/06 21:43

I am totally lost.

I have an xml script example as follows:

<?xml version="1.0" encoding="utf8" ?>
<starter>
<second>
<name>Silver</name>
</second>
</starter>

I have this printing to an array with the following php code:

class RSSParser {

var $struct = array(); // holds final structure
var $curptr; // current branch on $struct
var $parents = array(); // parent branches of current branch

function RSSParser($url) {
$this->curptr =& $this->struct; // set ref to base
$xmlparser = xml_parser_create();
xml_set_object($xmlparser, $this);
xml_set_element_handler($xmlparser, 'tag_open', 'tag_close');
xml_set_character_data_handler($xmlparser, 'cdata');
$fp = fopen($url, 'r');

while ($data = fread($fp, 4096))
xml_parse($xmlparser, $data, feof($fp))
|| die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xmlparser)),
xml_get_current_line_number($xmlparser)));

fclose($fp);
xml_parser_free($xmlparser);
}

function tag_open($parser, $tag, $attr) {
$i = count($this->curptr['children']);
$j = count($this->parents);
$this->curptr['children'][$i]=array(); // add new child element
$this->parents[$j] =& $this->curptr; // store current position as
parent
$this->curptr =& $this->curptr['children'][$i]; // submerge to
newly created child element
$this->curptr['name'] = $tag;
if (count($attr)>0) $this->curptr['attr'] = $attr;
}

function tag_close($parser, $tag) {
$i = count($this->parents);
if ($i>0) $this->curptr =& $this->parents[$i-1]; // return to
parent element
unset($this->parents[$i-1]); // clear from list of parents
}

function cdata($parser, $data) {
$data = trim($data);
if (!empty($data)) {
$this->curptr['value'] .= $data;
}
}

}

$myparser = new RSSParser('CreditCardBank.xml');

echo "<pre>";
$results = ($myparser->struct);
print_r($results);

-----

I get the following array:

[1] => Array
(
[name] => STARTER
[children] => Array
(
[0] => Array
(
[name] => NAME
[value] => Silver
Person&
)

)

)

-------

I need to be able to take the above array results and use them to
populate a menu, yet at the same time create ANOTHER array that
cleanses the : [value] => Silver Person& to remove the capitol
letters, spaces and charachters other than hyphens, letters and
numbers. I need the new array to show something like Silver Person& ==>
SilverPerson

Is this EVEN possible??

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация