473,378 Members | 1,360 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

So lost, xml, php, arrays help pls!

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??

Jun 14 '06 #1
0 1055

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: millw0rm | last post by:
Hi, here is the complete detail what i m trying 2 do. i got around 2000+ images with size/desp/image_no/slno etc TABLE `sheet1` ( `SlNo` int(11) NOT NULL auto_increment, `Image No` double...
35
by: Troll | last post by:
Hi, I need to write a script which reads some data and reports the findings. Just to give you an idea the structure is similar to the following. Data input example: HEADING 1 **********...
0
by: Al Caponi | last post by:
Hi all, There is a limitation on Win98 when a client app using mm.mysql driver doing extensive queries to MySQL 3.23.x frequently encounters a connection lost error. Error msg is something...
27
by: jacob navia | last post by:
Has anyone here any information about how arrays can be formatted with printf? I mean something besides the usual formatting of each element in a loop. I remember that Trio printf had some...
2
by: Raghu Raman | last post by:
Hi, In javascript file i store 3 values under a single cookie array ,like var myarray = new Array(null); myarray = "field_1"; myarray = "field_2"; myarray = "field_3"; document.cookie...
3
by: c++dummy | last post by:
I got this project for my class and I'm totally lost as to how to copy the 1d array with the bone name into a 2d array using this supposed strncpy function I'm supposed to create. I believe the...
9
by: jyohere | last post by:
Can anyone explain in detail why arrays are implemented as objects in java.And wat do we mean by arrays of arrays in java.....am not getting it completely....how does arrays differ from other...
6
by: annerhexian | last post by:
hi.. pls help me... im just new in php and i wish i could learn more.. i needed it for one day or two..hope u can reconsider my questions to you.. pls do help me.. i want my row array will be...
2
by: kenrocks | last post by:
well my problem is that I can 't figure how to arrange strings in arrays in an alphabetical order. pls.. answer asap..thx..:)
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.