|
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??
[Back to original message]
|