Hiya!
I'm trying to include my blog- hosted at blogger.com - to my website. The blog is in an rss-feed. Blogger includes the tags that I use in the blog as they are, <a>, <br/> and <img> for example. When I try to read the blogs, it outputs the title and the author correctly, but the description that contains those tags doesn't show as it should.
Here's the php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Dirtybird Rexx v2</title>
</head>
<body>
<div id="container">
<div id="blue">
<p>Latest blogs:<br />
<?php
if(!($xmlparser = xml_parser_create())){
die("Cannot create parser");
}
$postcount = 0;
$current = "";
function start_tag($parser, $name, $attribs){
global $current;
$current = $name;
global $postcount;
global $postdata;
}
function end_tag($parser, $name){
global $postcount;
if($name=="ITEM"){
$postcount ++;
}
global $postdata;
}
function tag_contents($parser, $data){
global $current;
global $postcount;
global $postdata;
$data = str_replace("ä", "ä", $data);
$data = str_replace("Ä", "Ä", $data);
$data = str_replace("ö", "ö", $data);
$data = str_replace("Ö", "Ö", $data);
if($current == "TITLE"){
$postdata[$postcount]["title"] = $data;
}
if($current == "AUTHOR"){
$postdata[$postcount]["author"] = $data;
}
if($current == "DESCRIPTION"){
$postdata[$postcount]["description"] = $data;
}
}
xml_set_element_handler($xmlparser, "start_tag", "end_tag");
xml_set_character_data_handler($xmlparser, "tag_contents");
$filename = "http://dirtybirdrexx.blogspot.com/rss.xml";
if (!($fp = fopen($filename, "r"))){
die("cannot open ".$filename);
}
while ($data = fread($fp, 8192)){
$data = eregi_replace(">"."[[:space:]]+"."< ",">< ",$data);
if (!xml_parse($xmlparser, $data, feof($fp))) {
$reason = xml_error_string(xml_get_error_code($xmlparser));
$reason .= xml_get_current_line_number($xmlparser);
die($reason);
}
}
xml_parser_free($xmlparser);
for ($i=0;$i<$postcount; $i++){
echo "<br /><strong>".$postdata[$i]["title"]."</strong> (by ".($postdata[$i]["author"]).")";
}
?>
</p>
</div>
<div id="grey">
<h2>all blogs</h2>
<?php
for ($i=0;$i<$postcount; $i++){
echo "<h2>".$postdata[$i]["title"]."</strong> (by ".($postdata[$i]["author"]).")</h2>";
echo "<p>".$postdata[$i]["description"]."</p>";
}
?>
</div>
</div>
</body>
</html>
... and xml can be found at http://dirtybirdrexx.blogspot.com/rss.xml
This code outputs this:
Latest blogs:
About Subliminal EP (by the Slowdowns)
The Beginning (by Dirtybird Rexx)
all blogs
About Subliminal EP (by the Slowdowns)
- the Slowdowns
The Beginning (by Dirtybird Rexx)
- Jyri of DBR
When it should output a lot more text before those signatures (the Slowdowns and Jyri of DBR). I think it has something to do with the <br /> -tags just before the signatures. So I need to find the solution how to stop the description from breaking. I've tried the str_replace function before putting $data to the $postdata -array, but it didn't work.
Help, anyone?
- Jyri