Wednesday, April 28, 2010

How to Validate RSS or ATOM feed using simple PHP Script

Here a simple function to Validate Feed URL,

  1. function getFeedStatus ($url) {
  2.     $ch = curl_init();
  3.     curl_setopt ($ch, CURLOPT_URL, $url);
  4.     curl_setopt ($ch, CURLOPT_HEADER, 0);
  5.     curl_setopt ($ch, CURLOPT_TIMEOUT, 30);
  6.     curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
  7.     curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
  8.  
  9.     $string = curl_exec($ch);
  10.     curl_close($ch);
  11.  
  12.     if (strpos($string, '<feed') > 0 && strpos($string, '</feed')) {
  13.             return "ATOM";
  14.     } else if (strpos($string, '<channel') > 0 && strpos($string, '</channel')) {
  15.             return "RSS";
  16.     } else {
  17.             return "INV";
  18.     }
  19. }
  20.  

4 comments:

  1. Great Article… I love to read your articles because your writing style is too good, its is very very helpful for all of us and I never get bored while reading your article because, they are becomes a more and more interesting from the starting lines until the end.
    Best Devops Training in pune
    Devops Training in Bangalore
    Microsoft azure training in Bangalore
    Power bi training in Chennai

    ReplyDelete

All rights reserved for all the posts. Please inform us on idhanu@gmail.com if you are publishing post in this without modifying. Code snippets are free to use, if not explicitly mentioned.