# Help with file\_exists in PHP

**URL:** <https://forum.kirupa.com/t/help-with-file-exists-in-php/267830>\
**Category:** programming\
**Created:** [August 6, 2008, 7:09am UTC](https://forum.kirupa.com/t/help-with-file-exists-in-php/267830 "2008-08-06T07:09:50Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![SpawnOfJon](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/spawnofjon/32/3308_2.png) [@SpawnOfJon](https://forum.kirupa.com/u/SpawnOfJon)\
**Post date:** [August 6, 2008, 7:09am UTC](https://forum.kirupa.com/t/help-with-file-exists-in-php/267830/1 "2008-08-06T07:09:50Z")

</div>

I wrote a simple XML parser that takes a feedburner feed and loops out a few titles and permalinks.

As a failsafe to keep the whole page from breaking if the feed is down or something I wanted to add an if statement using file\_exists. But it keeps returning false even though the url is correct.

I have limited PHP knowledge. Am I doing this right? Is there a better way to do this?

\<?php

```
$request_url = "http://feeds.feedburner.com/feed";
if(file_exists($request_url)) {
    $xml = simplexml_load_file($request_url) or die("feed not loading");

    for($i=0;$i&lt;5;$i++) {
        $title = $xml-&gt;channel-&gt;item[$i]-&gt;title;
        $link = $xml-&gt;channel-&gt;item[$i]-&gt;link;
        
        echo"&lt;a href=".'"'.$link.'"'."&gt;";
        
        echo($title);
        echo"&lt;/a&gt;&lt;br /&gt;";
    };
} else {
    echo "Cannot locate blog feed.";
}

```

?\>

```php
<?php 
 
    $request_url = "http://feeds.feedburner.com/feed";
    if(file_exists($request_url)) {
        $xml = simplexml_load_file($request_url) or die("feed not loading");
    
    
        for($i=0;$i<5;$i++) {
            $title = $xml->channel->item[$i]->title;
            $link = $xml->channel->item[$i]->link;
            
            echo"<a href=".'"'.$link.'"'.">";
            
            echo($title);
            echo"</a><br />";
        };
    } else {
        echo "Cannot locate blog feed.";
    }
?>

```

btw, this editor is giving me grief. . . I apologize for the repeated code. It won’t let me remove it.
