index = 0; $this->pointer[] = &$this->obj_data; $this->xml_data = $xml_data; $this->xml_parser = xml_parser_create( "UTF-8" ); xml_parser_set_option( $this->xml_parser, XML_OPTION_CASE_FOLDING, false ); xml_set_object( $this->xml_parser, &$this ); xml_set_element_handler( $this->xml_parser, "_startElement", "_endElement"); xml_set_character_data_handler( $this->xml_parser, "_cData" ); xml_parse( $this->xml_parser, $this->xml_data, true ); xml_parser_free( $this->xml_parser ); } function _startElement( $parser, $tag, $attributeList ) { foreach( $attributeList as $name => $value ) { $value = $this->_cleanString( $value ); $object->$name = $value; } eval( "\$this->pointer[\$this->index]->" . $tag . "[] = \$object;" ); eval( "\$size = sizeof( \$this->pointer[\$this->index]->" . $tag . " );" ); eval( "\$this->pointer[] = &\$this->pointer[\$this->index]->" . $tag . "[\$size-1];" ); $this->index++; } function _endElement( $parser, $tag ) { array_pop( $this->pointer ); $this->index--; } function _cData( $parser, $data ) { if( trim( $data ) ) { $this->pointer[$this->index] = trim( $data ); } } function _cleanString( $string ) { return utf8_decode( trim( $string ) ); } } $filename = "poll.xml"; $xmlC = new XmlC(); $xml_data = file_get_contents( $filename ); $xmlC->Set_XML_data( $xml_data ); //print_r( $xmlC->obj_data ); //print "Blah blah

blah"; //array pollcontent $pollcontent=( $xmlC->obj_data->poll); //print_r ($pollcontent[0]->topic); $categories=$pollcontent[0]->category; $data=$pollcontent[0]->data; //print_r($categories); $img=imagecreate(320,220); $white = imagecolorallocate($img, 255, 255, 255); $black = imagecolorallocate($img,0,0,0); // draw a white circle //imagearc($img, 100, 100, 150, 150, 0, 360, $black); imagerectangle($img,105,05,315,215,$black); imagestring($img,2,0,0,"Poll:",$black); imagestring($img,2,0,20,$pollcontent[0]->topic,$black); $tmpy=30; // then we put the various categories down, bearing in mind that the first one starts at y=50 pixels foreach( $categories as $name => $value ) { imagestring($img,2,0,20+$tmpy,$value->name,$black); $tmpy+=20; } // Now we need to extract the results from somewhere. $filename=$data[0]->filename; //imagestring($img,2,0,20+$tmpy,$filename,$black); //$myrawresults=fopen($filename,"r"); $fcontents = file($filename); //..$rawresults=array(); // for every pair of lines in the file // just want frequency ratings of each thing // only concentrating on votes for the moment I think $resultcategories=array(); $resultcategories[0]=array(); $resultcategories[1]=array(0,1,2,3,4,5,6,7,8,9); $resultvotes=array(); for ($foo=0; $foo<10; $foo++){ $resultvotes[$foo]=0; } $runningmaxvalue=0; foreach ($fcontents as $index=>$value){ $tmparray=explode("=",$value); if (strstr($tmparray[0],"vote")){ //imagestring($img,2,0,20+$tmpy,$tmparray[1],$black); //echo $tmparray[0]; //echo $tmparray[1]; $tmparray[1]=chop($tmparray[1]); //echo "Resultvotes ***$tmparray[1]***"; $resultvotes[$tmparray[1]]=$resultvotes[$tmparray[1]]+1; if($resultvotes[$tmparray[1]]>$runningmaxvalue){ $runningmaxvalue=$resultvotes[$tmparray[1]]; } } } /// now print out the votes... $initialy=53; foreach ( $resultvotes as $name => $value ){ // coordinates should be... starting at fifty, and adding 20 each time. if($value>0){ $resultantx=108+$value/$runningmaxvalue*200; imagefilledrectangle($img,108,$initialy,$resultantx,$initialy+5,$black); } $initialy+=20; } imagestring($img,2,270,200,"max:$runningmaxvalue",$black); //fclose($myrawresults); // output image in the browser header("Content-type: image/png"); imagepng($img); // free memory imagedestroy($img); ?>