|
Schön, dass Du hier bist.
Auf dieser Seite habe ich es endlich mal geschafft, die Bilder ins
Netz zu stellen, die ich mit meiner Digitalkamera
gemacht habe.
(es hat ja auch nur ca. 2 Jahre gedauert ;->)
Jetzt aber viel Spaß,
Claus
// Where we're getting our file from
// NOTE: Replace the XXXX in the line below with your e-mail address,
// preferably substituting %40 for the @ symbol. It may work without
// the substitution, but no guarantees.
$file = 'http://setiathome.ssl.berkeley.edu/fcgi-bin/fcgi?cmd=user_xml&email=claus.teutsch%40gmx.de';
// Our context - what sort of tag are we in right now?
$context = '';
// Some parsing functions
function setiparse($parser, $file) {
// Attempt to open the file.
if (!($fp = @fopen($file, 'r'))) {
print ("Seti-Server nicht erreichbar");
return false;
}
// Attempt to read and parse the file, and if it doesn't parse, then
// we need to go ahead and return false, to signify failure.
while ($data = fread($fp, 4096)) {
if (!xml_parse($parser, $data, feof($fp))) {
return false;
}
}
// At this point, we must have succeeded and ran out of file, so
// close the file handle and return true.
fclose($fp);
return true;
} // end setiparse
function start_element($parser, $name, $attrs) {
// start_element gets called any time a new tag starts in the XML
global $context;
// For all intensive purposes, we really don't care unless the name
// is A, since that would be a link. We'll just skip those.
// Otherwise, we set the context to be the name.
if ($name != 'a') {
$context = $name;
}
} // end start_element
function stop_element($parser, $name) {
// stop_element is called any time there is a closing XML tag.
// If we're ending our current context, we'll wipe out context just
// to be safe.
global $context;
if ($name == $context) {
$context = '';
}
} // end stop_element
function char_data($parser, $data) {
// This is where we'll actually get data. I could probably write a
// hackish means of making this more 'efficient', but I'll be
// explicit so that's it's obvious as to what's going on.
global $context;
// Based on our context, we'll print out a specific leading field,
// then the char_data, then a break. Fortunately for us, the SETI
// XML file presents data in a nice, logical fashion, so we're good.
// These are just the tags that I was interested in, and it's
// relatively easy to add more tags - check out the XML doc and/or
// the DTD on the SETI page for more information.
switch ($context) {
case 'NUMRESULTS':
print "SETI Wu's: $data \n";
break;
default:
break;
} // switch
} // end char_data
// Create Expat parser
$parser = xml_parser_create();
// Set handler functions
xml_set_element_handler($parser, "start_element", "stop_element");
xml_set_character_data_handler($parser, "char_data");
// Parse the file
$ret = setiparse($parser, $file);
if(!$ret) {
die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($parser)),
xml_get_current_line_number($parser)));
}
// Free parser
xml_parser_free($parser);
?>
|