Hi David
Could you have a look at code below it works fine with php4 but all we get now with php5 is a blank page and an Undefined index message. Ive tried turning off error reporting but no differance.
Chris
<?php
require 'MagicParser.php';
$url = "http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/front_page/rss.xml";
$page = $_GET["page"];
$counter = 0;
$itemsOnPage = 20;
// default to the first page
if (!$page) $page = 1;
function myRecordHandler($item)
{
global $page;
global $counter;
global $itemsOnPage;
$counter++;
// return false whilst parsing items on previous pages
if ($counter < (($page-1)*$itemsOnPage)) return false;
// display the item
print "<div align='center'>";
print "<table border='0' cellpadding='0' cellspacing='0' width='100%'>";
print "<tr>";
print "<td height='5'></td>";
print "</tr>";
print "<tr>";
print "<td height='14'><p class='dir'><a target='_blank' href='".$item["LINK"]."'>".$item["TITLE"]."</a></p></td>";
print "</tr>";
print "<tr>";
print "<td bgcolor='#F5EFD3'><p class='adtext'>".$item["DESCRIPTION"]."</p></td>";
print "</tr>";
print "<tr>";
print "<td bgcolor='#F5EFD3' height='14'>";
print "<table border='0' cellpadding='0' cellspacing='0' width='100%'>";
print "<tr>";
print "<td width='356'><i><p class='adtext'>".$item["PUBDATE"]."</p></i></td>";
print "<td width='100'><p class='adtext' align='right'><a target='_blank' href='".$item["LINK"]."'><b><i>Read more</i></b></a></p></td>";
print "</tr>";
print "</table>";
print "</td>";
print "</tr>";
print "</table>";
print "</div>";
// return true if counter reaches current page * items on each page
return ($counter == ($page*$itemsOnPage));
}
// parse the xml feed
MagicParser_parse($url,"myRecordHandler","xml|RSS/CHANNEL/ITEM/");
?>
Hi David
I gave that a go and now get the following
Parse error: syntax error, unexpected ')', expecting T_STRING or T_VARIABLE or '$' in /var/www/vhosts/domain.co.uk/httpdocs/test1.php on line 5
Chris
Sorry, Chris - code should have been:
if (isset($_GET["page"]))
{
$page = $_GET["page"];
}
else
{
$page = 1;
}
Cheers,
David.
Still no luck David
Page appears to be parsing for a while but ends in blank page.
Have checked allow_url_fopen and thats set to local on, master on using phpinfo.php
Hi Chris,
Can you test whether or not the myRecordHandler function is being called - where you have:
function myRecordHandler($item)
{
...replace this with:
function myRecordHandler($item)
{
print_r($item);
Assuming that nothing is displayed, it would be worth just testing the fopen() and file downloading completely; as it may be some kind of timeout error.
The following script should just connect to the remote URL, retrieve and print the contents - so it should be displayed as XML by the browser:
<?php
$url = "http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/front_page/rss.xml";
$fp = fopen($url,"r");
if (!$fp) die("Could not open URL");
while(!feof($fp))
{
print fread($fp,1024);
}
fclose($fp);
?>
Cheers,
David.
David
With your fopen()test it resulted in...
Warning: fopen(http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/front_page/rss.xml) [function.fopen]: failed to open stream: Connection timed out in /var/www/vhosts/domain.co.uk/httpdocs/test2.php on line 3
Could not open URL
Chris
Hello Chris,
Thanks - that does indicate then that it is an fopen() problem. However, as it seems that URL wrappers ARE enabled; it would imply that there is something blocking access to external URLs from your server. Is this a new server; or just an upgrade of PHP on the same server?
It would be worth putting a request in to your hosting company support line at this point - just state that you are trying to use a PHP script with fopen() and a URL - do they know of any reason why it won't work? (copy the error message to them)...
Cheers,
David.
Looks like thats the problem David
Its a new server with NamesCo, before I move our sites over I've been running a copy test site to spot any problems before the move. (I hate moving servers!). I shall drop them a note and let you know how I get on.
Chris
Hi David
The response was quick, as it turns ou we needed to set up firewall rules to allow external feeds which has been done and has got them functioning now. I still get error messages when .$item["PUBDATE"]. OR .$item["LASTMOD"]. are missing so as a temp solution I've turned off error reporting.
Chris
Hi Chris,
The undefined index message is probably due to:
$page = $_GET["page"];
..so with warnings enabled, this would need to be replaced with:
if (isset())
{
$page = $_GET["page"];
}
else
{
$page = 1;
}
...and then you can get rid of this line:
if (!$page) $page = 1;
However, the main problem; as you have changed PHP installation is most likely that the new installation is not configured to allow fopen() of a URL. To confirm this, add the following on the last line of the PHP section:
print MagicParser_getErrorMessage();
If this confirms a file open error; check the following thread for more info and links about enabling URL Wrappers...
http://www.magicparser.com/node/189
Cheers,
David.