Feed not validating

Viewed 24

I am trying to collect content of feed using PHP. I get invalid url

https://www.keralapsc.gov.in/taxonomy/term/198/feed feed is not validating https://validator.w3.org/feed/check.cgi?url=https%3A%2F%2Fwww.keralapsc.gov.in%2Ftaxonomy%2Fterm%2F198%2Ffeed. What is the fix?


<div class="content">

 <form method="post" action="">
  <input type="text" name="feedurl" placeholder="Enter website feed URL">&nbsp;<input type="submit" value="Submit" name="submit">
 </form>
 <?php

 $url = "https://www.keralapsc.gov.in/taxonomy/term/125/feed/";
  if(isset($_POST['submit'])){
             if($_POST['feedurl'] != ''){
                          $url = $_POST['feedurl'];
                             }
              }

  $invalidurl = false;
  if(@simplexml_load_file($url)){
            $feeds = simplexml_load_file($url);
             }else{
                       $invalidurl = true;
                         echo "<h2>Invalid RSS feed URL.</h2>";
                        }


   $i=0;
   if(!empty($feeds)){

             $site = $feeds->channel->title;
               $sitelink = $feeds->channel->link;

               echo "<h2>".$site."</h2>";
                 foreach ($feeds->channel->item as $item) {

                            $title = $item->title;
                               $link = $item->link;
                               $description = $item->description;
                                  $postDate = $item->pubDate;
                                  $pubDate = date('D, d M Y',strtotime($postDate));


                                     if($i>=5) break;
                                    ?>
   <div class="post">
     <div class="post-head">
       <h2><a class="feed_title" href="<?php echo $link; ?>"><?php echo $title; ?></a></h2>
       <span><?php echo $pubDate; ?></span>
     </div>
     <div class="post-content">
       <?php echo implode(' ', array_slice(explode(' ', $description), 0, 20)) . "..."; ?> <a href="<?php echo $link; ?>">Read more</a>
     </div>
   </div>

   <?php
    $i++;
   }
 }else{
   if(!$invalidurl){
     echo "<h2>No item found</h2>";
   }
 }
 ?>
</div>


Above is the code to get content of feed. I think the feed is not validating so the code is not working. I cant find a fix for this. Which step I missed. I am not expert in programing. Thanks.

0 Answers
Related