I want to validate RSS feed URL before its process for parsing. I am using willvincent/feeds library for this.
$feed = Feeds::make($rssurl);
$items = $feed->get_items();
I am parsing RSS feed like above.
So how can validate the RSS feed URL before parsing using willvincent/feeds library.
'willvincent/feeds' is just a service provider for Laravel.
You should refer to SimplePie documentation, and use the error() method to check if url throws errors. This method holds the error description.
$feed = Feeds::make('http://some-bogus-feed-url');
if($feed->error()){
//handle the feed error
}
Related
When I try to parse a specific RSS feed using the native RSS widget for WordPress I receive the following error:
RSS Error: A feed could not be found at
http://trustbox.trustpilot.com/r/harringtonbrooks.co.uk.xml. A feed
with an invalid mime type may fall victim to this error, or SimplePie
was unable to auto-discover it.. Use force_feed() if you are certain
this URL is a real feed.
I have validated the feed using the http://validator.w3.org/feed/ and it states that the feed is valid. I belive that the mime type is also correct for the feed - type="application/rss+xml"
After consulting the SimplePie documentation this code is suggested as the fix - however I am clueless as to where this code would actually be implemeted within the WordPress installation.
$feed = new SimplePie();
$feed->set_feed_url('MY FEED URL');
$feed->force_feed(true);
$feed->init();
$feed->handle_content_type();
echo $feed->get_title();
Alternatively are there any other suggestions for getting this RSS feed to actually be parsed by the reader?
This is my fanpage: https://www.facebook.com/kidsvideo.us
And here is my rss url: https://www.facebook.com/feeds/page.php?format=atom10&id=1433882270183943
There is error encoding when use this rss, I use php simplepie and tried feedburner with the same error: feeds.feedburner.com/KidsVideosFacebookWall
Any solution?
The solution is: Facebook use html entity in the xml. Simple use html_entity_decode() to decode the "error content".
Hi can Anyone tell me how to process this rss feed in php
http://www.ft.com/rss/companies/travel-leisure
when i am executing the below lines
$rss = new DOMDocument();
$rss->load('http://www.ft.com/rss/companies/travel-leisure');
it is giving an error
A PHP Error was encountered
Severity: Warning
Message: DOMDocument::load(): Opening and ending tag mismatch: link line 8 and head in http://www.ft.com/rss/companies/travel-leisure, line: 11
Thanks
If you request http://www.ft.com/rss/companies/travel-leisure without a User-Agent HTTP request header, you can get an error message back (under a 200 OK status).
This is a bug in FT's website.
As a work around, I suggest using cURL to fetch the data, and then feed a string into DOMDocument.
Why not use a dedicated library like SimplePie to process your RSS feed ?
$feed = new SimplePie('http://www.ft.com/rss/companies/travel-leisure');
$feed->init();
$feed->handle_content_type();
foreach ($feed->get_items() as $item) {
$permalink = $item->get_permalink();
$title = $item->get_title();
// Do what you want...
}
I have not tested this code, it's just to show you an example of use. Here the documentation and an example for more explanations.
I'm a newbie at CI, and I want to retrieve XML data from web services WebLogic, the server that is located at: http://services.insw.go.id/web-services/nsw?operation.invoke=getListGA . I want to to get the XML response from the server. How should I do this?
I made this function on controllers (resttest.php)
public function getRest()
{
$this->rest->initialize(array('server' => 'http://services.insw.go.id'));
$lartas = $this->rest->get('web-services/nsw',array('operation.invoke' => 'getListGA'),'xml');
die(var_dump($lartas));
}
Sometimes I get an error like "array(0) { }" and if I refresh, I get all HTML view, the same as when I browse to: http://services.insw.go.id/web-services/nsw?operation.invoke=getListGA
Am I wrong, or missing some step, or do you have any suggestion about how to change this code?
It looks as if your webservice is using SOAP (simple object access protocol). This is not REST. You'll want to use PHP's built in Soap extension with the SoapClient class. This way it's easy to post a XML "request" to that page which will return xml results rather than a html view (I assume).
Check Soap the soap extension is loaded on your server
Read about the SoapClient http://php.net/manual/en/class.soapclient.php
See if that webservice offers a WSDL (web service description language) file.
Create an instance of a soap client, using the wsdl and call the function you require.
Simple example from PHP.net
$client = new SoapClient("http://localhost/code/soap.wsdl");
$something = $client->HelloWorld(array());
echo $something->HelloWorldResult;
To get a xml response, you do not need Codeigniter. Specifically it provide WSDL. At http://services.insw.go.id/web-services/nsw you can find the example as
String wsdlUrl = "http://services.insw.go.id:80/web-services/nsw?WSDL";
So the WSDL API would be http://services.insw.go.id:80/web-services/nsw?WSDL
Then you can check this page to see how to install soap for your php.
Then you can get a xml response by the following code:
$client = new SoapClient('http://services.insw.go.id:80/web-services/nsw?WSDL');
//var_dump($client->__getFunctions());
$response = $client->getListGA();
echo $response;
these code do not need Codeigniter.
Note: $client->__getFunctions() will show you all functions that the WSDL support and the parameters the functions need.
Good luck
I have following link http://gdata.youtube.com/feeds/api/videos/tYMYv1zsAxE and it return an xml file in which is located noembed tag in case the video is not embeddable.
i want to create a loop on list of videos to check which is embeddable and which is not.
Based on your clarification, it sounds like you're asking a question about parsing XML. Here's an alternative: get back JSON, and parse that. You can make a request like
http://gdata.youtube.com/feeds/api/videos/tYMYv1zsAxE?v=2&alt=jsonc&prettyprint=true
and then look at the data->accessControl->embed element within the JSON response.
Or, you know, just parse and access the YouTube API XML exactly like you'd parse the XML from any other source. There's nothing magic going on with the YouTube API XML.
$vidID = "tYMYv1zsAxE";
$url="http://gdata.youtube.com/feeds/api/videos/$vidID?v=2&alt=jsonc&prettyprint=true";
$json = file_get_contents($url, true);
$json_output = json_decode($json);
echo $json_output->data->accessControl->embed;
Simple way to check if youtube video is embeddable.
Thanks to #Jeff Posnick