Hi there,
I am creating a little RSS reader. I don't have any PHP space at the moment so I am doing it locally so I will just show you the script.
I want the RSS to be shown in an image and I am using the following script, but whenever it is exected it just shows the image with no text.
What could be the problem?
Thanks...
[EDIT]
Just had a brainwave, I think I should write them to a text file first....
I am creating a little RSS reader. I don't have any PHP space at the moment so I am doing it locally so I will just show you the script.
I want the RSS to be shown in an image and I am using the following script, but whenever it is exected it just shows the image with no text.
What could be the problem?
Code:
<?php
class RSSParser {
var $insideitem = false;
var $tag = "";
var $title = "";
function startElement($parser, $tagName, $attrs) {
if ($this->insideitem) {
$this->tag = $tagName;
} elseif ($tagName == "ITEM") {
$this->insideitem = true;
}
}
function endElement($parser, $tagName) {
if ($tagName == "ITEM") {
$slogan = vsprintf("%s",(trim($this->title)));
$this->title = "";
$this->insideitem = false;
}
}
function characterData($parser, $data) {
if ($this->insideitem) {
switch ($this->tag) {
case "TITLE":
$this->title .= $data;
break;
case "DESCRIPTION":
$this->description .= $data;
break;
case "LINK":
$this->link .= $data;
break;
}
}
}
}
$xml_parser = xml_parser_create();
$rss_parser = new RSSParser();
xml_set_object($xml_parser,&$rss_parser);
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
$fp = fopen("http://ws.audioscrobbler.com/1.0/user/Cool_Guy/recenttracks.rss","r")
or die("Error reading RSS data.");
while ($data = fread($fp, 4096))
xml_parse($xml_parser, $data, feof($fp))
or die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
fclose($fp);
xml_parser_free($xml_parser);
$im = imagecreatetruecolor(400, 100);
$white = imagecolorallocate($im, 255, 255, 255);
$blue = imagecolorallocate($im, 0, 0, 147);
$font = "VERDANA.TTF";
imagefill($im, 0, 0, $white);
imagerectangle($im, 0, 0, 399, 99, $blue);
imagettftext($im, 8, 0, 5, 15, $blue, $font, $slogan);
header("Content-Type: image/png");
imagepng($im);
imagedestroy($im);
?>
Thanks...
[EDIT]
Just had a brainwave, I think I should write them to a text file first....
Last edited: