473,388 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

open in new window from RSS news feed help

Cam
Hi I'm using this simple rss parser that i would like to have open in
another window. But I'm very much a beginner in php scripting.

Here is the script on the page

<?php

require('./class.phpnet.php');

$phpxml = new phpnet_news("http://au.biz.yahoo.com/financenews/htt/financenews.xml",
1);
$news = $phpxml->get_headlines(8);

?><?php
for ($i = 0; $i < sizeof($news['title']); $i++) {
echo '<li><a href="' . $news['link'][$i] . '">' . $news['title'][$i].
'</a></li>';
echo "\n";
}
?>
------------------

And this is the main script

class phpnet_news {

var $titles, $descriptions, $links, $ccdate;

function phpnet_news($url, $ignore_cache)
{
$url = parse_url($url);
$data = '';
$this->get_rss_file($url['host'], $url['path'], &$data,
$ignore_cache);
$this->parse_contents(&$data);
unset($data);
}

function is_cache($file, $ignore_cache)
{
if ($ignore_cache)
return 0;

$file = '.' . $file . '.cache';

$fp = fopen($file, 'a+');
fseek($fp, 0);

$rd = fread($fp, filesize($file));
fclose($fp);

if (time() - $rd > 300)
return 0;
else
return 1;
}

function update_cache($file, &$data, $ignore_cache)
{
if ($ignore_cache)
return 0;

$fp = fopen('.' . $file, 'w');
fwrite($fp, $data);
fclose($fp);

$fp = fopen('.' . $file . '.cache', 'w');
fwrite($fp, time());
fclose($fp);
}

function get_rss_file($host, $path, &$data, $ignore_cache)
{
if (!$this->is_cache($path, $ignore_cache)) {
$fp = @fsockopen($host, 80, $errno, $errstr, 30);
if (!$fp) {
fclose($fp);
echo "$errstr ($errno)\n";
} else {
fwrite($fp, "GET $path HTTP/1.1\r\nHost: $host\r\n\r\n");
while (!feof($fp))
{
$data .= fread($fp, 4096);
}
fclose($fp);

$data = str_replace("\n", "", $data);

$this->update_cache($path, &$data, $ignore_cache);
}
} else {
$fp = fopen('.' . $path, 'r');
$data = fread($fp, filesize('.' . $path));
fclose($fp);
}
}

function parse_contents(&$data)
{
preg_match_all("|<description>(.*)</description>|U", $data,
$this->descriptions);
preg_match_all("|<title>(.*)</title>|U", $data, $this->titles);
preg_match_all("|<link>(.*)</link>|U", $data, $this->links);
preg_match_all("|<cc:date>(.*)</cc:date>|U", $data, $this->ccdate);
}

function get_headlines($num)
{
for ($i = 0; $i < ($num); $i++) {
$news['title'][$i] = &$this->titles[1][$i+1];
$news['link'][$i] = &$this->links[1][$i+1];
$news['description'][$i] = &$this->descriptions[1][$i+1];
$news['ccdate'][$i] = &$this->ccdate[1][$i];
}
return $news;
}
}

?>

-------------------------------------
Any help would be greatly appreciated

Thanks
Jul 17 '05 #1
1 1839
Cam wrote:
Hi I'm using this simple rss parser that i would like to have open in
another window. But I'm very much a beginner in php scripting.

Here is the script on the page

<?php

require('./class.phpnet.php');

$phpxml = new phpnet_news("http://au.biz.yahoo.com/financenews/htt/financenews.xml",
1);
$news = $phpxml->get_headlines(8);

?><?php
for ($i = 0; $i < sizeof($news['title']); $i++) {
echo '<li><a href="' . $news['link'][$i] . '">' . $news['title'][$i].
'</a></li>';
echo "\n";
}
?>
------------------

And this is the main script

class phpnet_news {

var $titles, $descriptions, $links, $ccdate;

function phpnet_news($url, $ignore_cache)
{
$url = parse_url($url);
$data = '';
$this->get_rss_file($url['host'], $url['path'], &$data,
$ignore_cache);
$this->parse_contents(&$data);
unset($data);
}

function is_cache($file, $ignore_cache)
{
if ($ignore_cache)
return 0;

$file = '.' . $file . '.cache';

$fp = fopen($file, 'a+');
fseek($fp, 0);

$rd = fread($fp, filesize($file));
fclose($fp);

if (time() - $rd > 300)
return 0;
else
return 1;
}

function update_cache($file, &$data, $ignore_cache)
{
if ($ignore_cache)
return 0;

$fp = fopen('.' . $file, 'w');
fwrite($fp, $data);
fclose($fp);

$fp = fopen('.' . $file . '.cache', 'w');
fwrite($fp, time());
fclose($fp);
}

function get_rss_file($host, $path, &$data, $ignore_cache)
{
if (!$this->is_cache($path, $ignore_cache)) {
$fp = @fsockopen($host, 80, $errno, $errstr, 30);
if (!$fp) {
fclose($fp);
echo "$errstr ($errno)\n";
} else {
fwrite($fp, "GET $path HTTP/1.1\r\nHost: $host\r\n\r\n");
while (!feof($fp))
{
$data .= fread($fp, 4096);
}
fclose($fp);

$data = str_replace("\n", "", $data);

$this->update_cache($path, &$data, $ignore_cache);
}
} else {
$fp = fopen('.' . $path, 'r');
$data = fread($fp, filesize('.' . $path));
fclose($fp);
}
}

function parse_contents(&$data)
{
preg_match_all("|<description>(.*)</description>|U", $data,
$this->descriptions);
preg_match_all("|<title>(.*)</title>|U", $data, $this->titles);
preg_match_all("|<link>(.*)</link>|U", $data, $this->links);
preg_match_all("|<cc:date>(.*)</cc:date>|U", $data, $this->ccdate);
}

function get_headlines($num)
{
for ($i = 0; $i < ($num); $i++) {
$news['title'][$i] = &$this->titles[1][$i+1];
$news['link'][$i] = &$this->links[1][$i+1];
$news['description'][$i] = &$this->descriptions[1][$i+1];
$news['ccdate'][$i] = &$this->ccdate[1][$i];
}
return $news;
}
}

?>

-------------------------------------
Any help would be greatly appreciated

Thanks

You need to use the client browser to open the new (RSS) page in a new
window, look at the docs for the onclick event
Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: kelli | last post by:
I am using an iframe to feed an RSS but when i click on the link on the iframe it opens the link on the iframe instead of opening it on the parent window or a new window.. the code is in php.. its...
18
by: Paul | last post by:
I link to a web site from an Excel spreadsheet. The page i link to is getCookie.asp which sets a cookie then returns back some html which opens a new window, to the same site but a different page...
4
by: google | last post by:
Hi there, I've searched high and low for this, but it seems most people are looking to establish (and control) the relationship between a parent browser window and it's associated child window...
2
by: mg | last post by:
window.open (URLTarget, windowName, height=720,width=975,resizable=yes, ... lets me open a new WebForm with a specified size using JavaScript. Is there a way of doing this from code behind;...
7
by: (PeteCresswell) | last post by:
I've got a UNC. It's something like H:\CDL\Attachments\Deal000023.InitialOffering.doc. I want to feed that UNC to MS Windows and let Windows worry about selecting which application to use to...
13
by: TLaufenberg | last post by:
I'm new to Javascript programming and I've run into a bit of a snag with making an XMLHttpRequest in the Safari browser. Actually, the request doesn't work in Firefox either but only when I use a...
4
by: Guy Cohen | last post by:
Hi all How do I show an existing aspx page to the user? I need an equivalent command to java's window.open in ASP.NET TIA Guy
4
by: Claire DURAND | last post by:
Hi, I try to open a distant (not local) XML file in PHP to read an RSS feed. I can open an HTML page and read it with the file() function. But as soon as I try with a RSS feed instead of...
1
by: news.microsoft.com | last post by:
Hi, I'm using the folowing code to export a Crystal Report directly to browser: Response.Clear() cr.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, False, "Filename")...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.