| |||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | #1 (permalink) |
| NamePros Regular | PHP include of script inside smarty template file I need help! Been trying for hours and also by googling and asking other people but don't get this shit to work. I have a php script that displays a feed from my blog. An example can be seen on netmarketing.us I want to set this up on my directories. My directories use the phplinkdirectory script which is done in smarty. If I try this in the template file: {php}include('rss.php');{/php} Nothing gets output as HTML. There is nothing in the source code at all. If I add this to the index.php: include('rss.php'); $tpl->assign('RSS', $RSS); And then use {$RSS} in the template file what happens is that it works but the feed gets displayed on the top of the file before all other HTML code and not where I want it. I really need some help on this and can pay if needed. The only solution I could think of is to use iframes that calls a php file and on that file I can run the script, but iframes are not good SEO wise ... The rss.php looks like this: Code:
<?php
/*
Created by Global Syndication's RSS Parser
http://www.globalsyndication.com/rss-parser
*/
set_time_limit(0);
#### Here is the feed URL:
$file = "http://www.jimwestergren.com/category/online-marketing/feed/";
$rss_channel = array();
$currently_writing = "";
$main = "";
$item_counter = 0;
function startElement($parser, $name, $attrs) {
global $rss_channel, $currently_writing, $main;
switch($name) {
case "RSS":
case "RDF:RDF":
case "ITEMS":
$currently_writing = "";
break;
case "CHANNEL":
$main = "CHANNEL";
break;
case "IMAGE":
$main = "IMAGE";
$rss_channel["IMAGE"] = array();
break;
case "ITEM":
$main = "ITEMS";
break;
default:
$currently_writing = $name;
break;
}
}
function endElement($parser, $name) {
global $rss_channel, $currently_writing, $item_counter;
$currently_writing = "";
if ($name == "ITEM") {
$item_counter++;
}
}
function characterData($parser, $data) {
global $rss_channel, $currently_writing, $main, $item_counter;
if ($currently_writing != "") {
switch($main) {
case "CHANNEL":
if (isset($rss_channel[$currently_writing])) {
$rss_channel[$currently_writing] .= $data;
} else {
$rss_channel[$currently_writing] = $data;
}
break;
case "IMAGE":
if (isset($rss_channel[$main][$currently_writing])) {
$rss_channel[$main][$currently_writing] .= $data;
} else {
$rss_channel[$main][$currently_writing] = $data;
}
break;
case "ITEMS":
if (isset($rss_channel[$main][$item_counter][$currently_writing])) {
$rss_channel[$main][$item_counter][$currently_writing] .= $data;
} else {
$rss_channel[$main][$item_counter][$currently_writing] = $data;
}
break;
}
}
}
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
if (!($fp = fopen($file, "r"))) {
die("could not open XML input");
}
while ($data = fread($fp, 4096)) {
if (!xml_parse($xml_parser, $data, feof($fp))) {
die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
}
}
xml_parser_free($xml_parser);
// output HTML
### NOT NEEDED #### print ("<div class=\"channelname\">" . $rss_channel["TITLE"] . "</div>");
if (isset($rss_channel["ITEMS"])) {
if (count($rss_channel["ITEMS"]) > 0) {
# SIFFRAN NUMMER 5 NEDAN ANGER HUR MÅNGA SKA VISAS
for($i = 0;$i < 5;$i++) {
if (isset($rss_channel["ITEMS"][$i]["LINK"])) {
print ("\n<div class=\"itemtitle\"><a href=\"" . $rss_channel["ITEMS"][$i]["LINK"] . "\">" . $rss_channel["ITEMS"][$i]["TITLE"] . "</a></div>");
} else {
print ("\n<div class=\"itemtitle\">" . $rss_channel["ITEMS"][$i]["TITLE"] . "</div>");
}
print ("<div class=\"itemdescription\">" . $rss_channel["ITEMS"][$i]["DESCRIPTION"] . "</div><br />"); }
} else {
print ("<b>There are no articles in this feed.</b>");
}
}
?>
|
| |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| SendScript V1 . Great File Sending Script!! | naqiboy | Scripts For Sale | 0 | 08-28-2005 12:58 PM |
| PHP Include Shop | GHOwner | For Sale / Advertising Board | 0 | 10-18-2004 05:13 PM |
| Domain Rating Script for Sale : $200.00 - only 10 scripts will be sold | fonzerelli_79 | Scripts For Sale | 3 | 08-31-2003 08:41 AM |