473,394 Members | 4,027 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,394 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 1840
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: 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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.