3 Replies - 550 Views - Last Post: 23 February 2013 - 10:57 AM Rate Topic: -----

#1 c9-adams  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 98
  • Joined: 12-December 11

XML and PHP widget

Posted 23 February 2013 - 08:37 AM

Hi guys,

I am currently trying to create a widget using XML and PHP however it works fine at home however it does not on other servers.

Here is a link to the widget - http://www.cems.uwe....idget/index.php

Here is what I have tried so far :

index.php

<!Doctype>
<!--    The aim of this document is to build a structure which makes use of three tabs which stores and retrieves rss feeds from 3 external files maing use of php to retrieve the rss feeds and then using xml to retrieve certain items within these xml files, inthis case the title, description and publication date.   -->
<html>
<head>
    <title></title>
	<!--  Including javascript file to improve interactivity and to allow content to be displayed without having to be navigated to another page.  -->
	<link rel="stylesheet" href="css/default.css" />
	<script src="js/jquery-1.2.6.pack.js" type="text/javascript"></script>
	<script src="js/myScript.js" type="text/javascript"></script>
</head>
<body>
<!--   Include external php file building the functions necessary for retrieveing and building upon the rss feeds    -->
<?php include("includes/functions.php"); ?>
<div id="wrap">

<ul id="nav">
<li><a href="#content_1" class="selected">Metalground</a></li>
<li><a href="#content_2">Metalhammer</a></li>
<li><a href="#content_3">MetalTalk</a></li>
</ul>

	<div id="mainContent">

		<div id="content_1"><!--    first tab     --->
			<?php getFeed("http://feeds.feedburner.com/metalunderground.xml");?>
		</div><!--end content 1-->

		<div id="content_2"><!--    second tab     --->
			<?php getFeed("http://feeds.feedburner.com/metalhammer/main"); ?>
		</div><!--end content 2-->

		<div id="content_3"><!--    third tab     --->
			<?php getFeed("http://metaltalk.net/rss.php"); ?>
		</div><!--end content 3-->

	</div><!--end main content -->

</div><!--end wrap-->
</body>
</html>




functions.php
<?php
// the function getFeed is used to retrieve the feed url created by the feed_url variable.
function getFeed($feed_url) {
	$content = file_get_contents($feed_url);
	
	//the content variable is created to get the contents of the file. For example, it will read and retrieve the content contained within certain unique tags.
	
	$x = new SimplexmlElement($content);
	//the SimpleXMLElement represents an element
	echo "<ul>";
	// for every entry that is found use xml to create unique tags which retrieves the title, description and publication of the entry.
	//an example of using xml is that you can create your own tags, are not restricted to particular vocabularies and you can style your tags to your own satisfaction.
	foreach($x->channel->item as $entry) {
		echo "
		
		<entry>
		<li>
		  <heading>" . $entry->title . "</heading>
		  <description><p> ". $entry->description . "</p></description>
		  <date><p> ". $entry->pubDate . "</p></date>
		</li>
		</entry>";
		}
	echo "</ul>";
}
?>



*note - the error i am getting is - "Warning: file_get_contents(http://feeds.feedburner.com/metalunderground.xml) [function.file-get-contents]: failed to open stream: Network is unreachable in includes/functions.php on line 4"

Is This A Good Question/Topic? 0
  • +

Replies To: XML and PHP widget

#2 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3608
  • View blog
  • Posts: 12,393
  • Joined: 12-December 12

Re: XML and PHP widget

Posted 23 February 2013 - 08:44 AM

What filename are you supplying as $feed_url? OOPs, I see them in your code.

Perhaps it is a permissions issue.

This post has been edited by andrewsw: 23 February 2013 - 08:47 AM

Was This Post Helpful? 0
  • +
  • -

#3 c9-adams  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 98
  • Joined: 12-December 11

Re: XML and PHP widget

Posted 23 February 2013 - 08:48 AM

what is a permission issue?

This post has been edited by c9-adams: 23 February 2013 - 08:49 AM

Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6075
  • View blog
  • Posts: 23,540
  • Joined: 23-August 08

Re: XML and PHP widget

Posted 23 February 2013 - 10:57 AM

Whenever something works on one machine but not another think configuration first.

So by your error

Quote

Warning: file_get_contents(http://feeds.feedburner.com/metalunderground.xml) [function.file-get-contents]: failed to open stream: Network is unreachable in includes/functions.php


file_get_contents is failing. So, what you do is go to the documentation and read, looking for possible causes of configuration issues. Check out the Notes section. Not sure that's the issue there, as your error is not what I'd expect (but I don't use file_get_contents); I would have expected something about wrappers not being enabled.

So let's look more closely at your error.

Quote

Network is unreachable


Well, that would seem to indicate there might be something wrong with the network on that machine; maybe an outbound port firewall issue. So you go to the command line on the machine where it's not working and see if you can reach the site from there. The simplest means of doing this would be using curl or wget command line utilities, but they may not be installed. telnet likely is installed, so you could try

telnet http://feeds.feedbur...underground.xml 80

and see if you're able to connect that way.
Was This Post Helpful? 2
  • +
  • -

Page 1 of 1