Read RSS feeds
Moderator: General Moderators
-
vidhyakrish
- Forum Newbie
- Posts: 10
- Joined: Mon Feb 27, 2012 11:21 am
Read RSS feeds
Hi
i am trying to read this rss feed
"https://www.myjobscotland.gov.uk/rssjob ... 6&co2=1158"
using this PHP code:
<?php
$rss = new SimpleXMLElement('https://www.myjobscotland.gov.uk/rssjob ... 6&co2=1158', null, true);
foreach($rss->xpath('jobs/job') as $item)
{ ?> <p><?php print $item->PositionTitle; ?> </p>
<p> <?php echo $item->GeographicalArea;}
?></p>
But have been unsuccessful reading.
Can anybody help on how to read this feed?
Thanks in advance.
P.S: I am a PHP newbie!
i am trying to read this rss feed
"https://www.myjobscotland.gov.uk/rssjob ... 6&co2=1158"
using this PHP code:
<?php
$rss = new SimpleXMLElement('https://www.myjobscotland.gov.uk/rssjob ... 6&co2=1158', null, true);
foreach($rss->xpath('jobs/job') as $item)
{ ?> <p><?php print $item->PositionTitle; ?> </p>
<p> <?php echo $item->GeographicalArea;}
?></p>
But have been unsuccessful reading.
Can anybody help on how to read this feed?
Thanks in advance.
P.S: I am a PHP newbie!
Re: Read RSS feeds
Where are you getting jobs/job from? $item->PositionTitle? $item->GeographicalArea?vidhyakrish wrote:Code: Select all
<?php $rss = new SimpleXMLElement('https://www.myjobscotland.gov.uk/rssjobfeed/rss.aspx?sourceagencyid=11506&co2=1158', null, true); foreach($rss->xpath('jobs/job') as $item) { ?> <p><?php print $item->PositionTitle; ?> </p> <p> <?php echo $item->GeographicalArea;} ?></p>
-
vidhyakrish
- Forum Newbie
- Posts: 10
- Joined: Mon Feb 27, 2012 11:21 am
Re: Read RSS feeds
Hi there,
sorry it should be 'channel/item' not 'jobs/job' .
Mistake!
thanks
sorry it should be 'channel/item' not 'jobs/job' .
Mistake!
thanks
Re: Read RSS feeds
So you fixed $item->PositionTitle and $item->GeographicalArea as well? Is it working now?
-
vidhyakrish
- Forum Newbie
- Posts: 10
- Joined: Mon Feb 27, 2012 11:21 am
Re: Read RSS feeds
No,
I tried to output $item->title and $item->description but getting the following errors :
Warning: SimpleXMLElement::__construct(https://www.myjobscotland.gov.uk/rssjob ... 6&co2=1158) [function.SimpleXMLElement---construct]: failed to open stream: Connection refused in /public_html/site/scripts/rss_myjobs.php on line 2
Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: I/O warning : failed to load external entity "https://www.myjobscotland.gov.uk/rssjob ... 6&co2=1158" in /public_html/site/scripts/rss_myjobs.php on line 2
Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /home/southlancs/public_html/site/scripts/rss_myjobs.php:2 Stack trace: #0 /public_html/site/scripts/rss_myjobs.php(2): SimpleXMLElement->__construct('https://www.myj...', 0, true) #1 {main} thrown in /public_html/site/scripts/rss_myjobs.php on line 2
I tried to output $item->title and $item->description but getting the following errors :
Warning: SimpleXMLElement::__construct(https://www.myjobscotland.gov.uk/rssjob ... 6&co2=1158) [function.SimpleXMLElement---construct]: failed to open stream: Connection refused in /public_html/site/scripts/rss_myjobs.php on line 2
Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: I/O warning : failed to load external entity "https://www.myjobscotland.gov.uk/rssjob ... 6&co2=1158" in /public_html/site/scripts/rss_myjobs.php on line 2
Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /home/southlancs/public_html/site/scripts/rss_myjobs.php:2 Stack trace: #0 /public_html/site/scripts/rss_myjobs.php(2): SimpleXMLElement->__construct('https://www.myj...', 0, true) #1 {main} thrown in /public_html/site/scripts/rss_myjobs.php on line 2
Re: Read RSS feeds
This is working fine for me:
Code: Select all
<?php
$rss = new SimpleXMLElement('https://www.myjobscotland.gov.uk/rssjobfeed/rss.aspx?sourceagencyid=11506&co2=1158', null, true);
foreach ($rss->channel->item as $job)
{
echo "<div>";
echo strip_tags($job->title) . "<br />";
echo strip_tags($job->description);
echo "</div>";
}-
vidhyakrish
- Forum Newbie
- Posts: 10
- Joined: Mon Feb 27, 2012 11:21 am
Re: Read RSS feeds
thanks for the code!
I just tried in another hosting account - which works fine with the same code!
But the one where i actually want it work - still displays the following error:
Warning: SimpleXMLElement::__construct(http://www.myjobscotland.gov.uk/rssjobf ... 6&co2=1158) [function.SimpleXMLElement---construct]: failed to open stream: Connection refused in /home/southlancs/public_html/site/scripts/rss_myjobs.php on line 3
Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: I/O warning : failed to load external entity "http://www.myjobscotland.gov.uk/rssjobf ... 6&co2=1158" in /public_html/site/scripts/rss_myjobs.php on line 3
Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /home/southlancs/public_html/site/scripts/rss_myjobs.php:3 Stack trace: #0 /public_html/site/scripts/rss_myjobs.php(3): SimpleXMLElement->__construct('http://www.myjo...', 0, true) #1 {main} thrown in public_html/site/scripts/rss_myjobs.php on line 3
I dont understand these errors, can you ?
Sorry to be a pain! is there something to do with settings/configuration/infrastructure as the same code works fine in different hosting server.
Cheers
I just tried in another hosting account - which works fine with the same code!
But the one where i actually want it work - still displays the following error:
Warning: SimpleXMLElement::__construct(http://www.myjobscotland.gov.uk/rssjobf ... 6&co2=1158) [function.SimpleXMLElement---construct]: failed to open stream: Connection refused in /home/southlancs/public_html/site/scripts/rss_myjobs.php on line 3
Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: I/O warning : failed to load external entity "http://www.myjobscotland.gov.uk/rssjobf ... 6&co2=1158" in /public_html/site/scripts/rss_myjobs.php on line 3
Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /home/southlancs/public_html/site/scripts/rss_myjobs.php:3 Stack trace: #0 /public_html/site/scripts/rss_myjobs.php(3): SimpleXMLElement->__construct('http://www.myjo...', 0, true) #1 {main} thrown in public_html/site/scripts/rss_myjobs.php on line 3
I dont understand these errors, can you ?
Sorry to be a pain! is there something to do with settings/configuration/infrastructure as the same code works fine in different hosting server.
Cheers
Re: Read RSS feeds
You may want to check allow_url_fopen :vidhyakrish wrote: ...Sorry to be a pain! is there something to do with settings/configuration/infrastructure as the same code works fine in different hosting server.
Cheers
http://us2.php.net/manual/en/filesystem ... -url-fopen
-
vidhyakrish
- Forum Newbie
- Posts: 10
- Joined: Mon Feb 27, 2012 11:21 am
Re: Read RSS feeds
just an update, as found the solution is with our server not allowing https: // blocked by firewalls and hence the error " connection refused".
cheers
cheers