Page 1 of 1
Read RSS feeds
Posted: Mon Feb 27, 2012 11:34 am
by vidhyakrish
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!
Re: Read RSS feeds
Posted: Mon Feb 27, 2012 11:58 am
by Celauran
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>
Where are you getting jobs/job from? $item->PositionTitle? $item->GeographicalArea?
Re: Read RSS feeds
Posted: Tue Feb 28, 2012 3:47 am
by vidhyakrish
Hi there,
sorry it should be 'channel/item' not 'jobs/job' .
Mistake!
thanks
Re: Read RSS feeds
Posted: Tue Feb 28, 2012 5:15 am
by Celauran
So you fixed $item->PositionTitle and $item->GeographicalArea as well? Is it working now?
Re: Read RSS feeds
Posted: Tue Feb 28, 2012 5:25 am
by vidhyakrish
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
Re: Read RSS feeds
Posted: Tue Feb 28, 2012 5:40 am
by Celauran
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>";
}
Re: Read RSS feeds
Posted: Tue Feb 28, 2012 5:53 am
by vidhyakrish
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
Re: Read RSS feeds
Posted: Tue Feb 28, 2012 2:44 pm
by temidayo
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
You may want to check allow_url_fopen :
http://us2.php.net/manual/en/filesystem ... -url-fopen
Re: Read RSS feeds
Posted: Tue Mar 06, 2012 6:34 am
by vidhyakrish
just an update, as found the solution is with our server not allowing https: // blocked by firewalls and hence the error " connection refused".
cheers