OK thanks, that already brought me a bit futher. I have now following PHP Code:
PHP Code:
<?php
class AmazonRezensionen {
var $Rating;
var $Summary;
var $Comment;
function AmazonRezensionen ($aa) {
foreach ($aa as $k=>$v)
$this->$k = $aa[$k];
}
}
function readRezension($CustomerReview) {
$data = implode("", file($CustomerReview));
$parser = xml_parser_create();
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
xml_parse_into_struct($parser, $data, $values, $tags);
xml_parser_free($parser);
// loop through the structures
foreach ($tags as $key=>$val) {
if ($key == "CustomerReview") {
$reviewranges = $val;
// each contiguous pair of array entries are the
// lower and upper range for each review
for ($i=0; $i < count($reviewranges); $i+=2) {
$offset = $reviewranges[$i] + 1;
$len = $reviewranges[$i + 1] - $offset;
$tdb[] = parseRezension(array_slice($values, $offset, $len));
}
} else {
continue;
}
}
return $tdb;
}
function parseRezension($amazonvalues) {
for ($i=0; $i < count($amazonvalues); $i++) {
$arez[$amazonvalues[$i]["tag"]] = $amazonvalues[$i]["value"];
}
return new AmazonRezensionen ($arez);
}
$db = readRezension("amazon.xml");
The output with print_r($db); would look like this:
PHP Code:
Array
(
[0] => amazonrezensionen Object
(
[Rating] => 5
[Summary] => the best to understand cities now and then
[Comment] => this book, published for the first time in 1978...
)
[1] => amazonrezensionen Object
(
[Rating] => 1
[Summary] => Pompous garbage
[Comment] => This book is the most pompous garbage...
)
[2] => amazonrezensionen Object
(
[Rating] => 5
[Summary] => Most Important Book on Urban Design Theory.
[Comment] => Colin Rowe proposes a form of inclusive...
)
)
But how do I get this into what I mentioned above. I have now idea how this while construktion would need to look like???
Please help
Thanx so far,
Flözen
Bookmarks