Jump to content

Recommended Posts

Hi everyone !

 

I've been trying to find a solution for days... please Help!

 

Basically i need to find an RSS feed on given webpage,  lets say: http://news.yahoo.com/rss

they don't provide a file extension like: topstories.rss, so the only way for it to work on any page, is to go to the file contents,

and parse the first line, if it is: <?xml ..... then consider it as a feed.

 

here is what i tried:

 

$contents = file_get_contents('http://news.yahoo.com/rss'); //Get all contents of the file,

 

$strText = preg_match_all(' Link regEx ', $contents , $value); //take out the links only.

$value = array_unique ($value[0]);

 

foreach($value as $key){

 

$content=file($key);

 

}

 

so the only problem is that: file(); takes the whole file in order to process it, so if the page has lets say 250 links , it would take FOREVER to get all those files, just because i need only 1st line. :-\

 

Question: is there a way to get only the 1st, 2nd line of the file, and Not loading it in full. or is there another way?

 

 

Thank you.

 

 

Link to comment
https://forums.phpfreaks.com/topic/50805-detect-rss-feeds-on-page/
Share on other sites

http://us2.php.net/manual/en/function.fread.php

 

If you have url_wrappers or something like that on you could use that.

 

cURL may help ???

 

http://us2.php.net/manual/en/function.fgets.php

 

That may also help as you can just get the first line.

 

Hope that helps. If all else fails, why not just check for that <?xml string first before parsing the links?

http://us2.php.net/manual/en/function.fread.php

 

If you have url_wrappers or something like that on you could use that.

 

cURL may help ???

 

http://us2.php.net/manual/en/function.fgets.php

 

That may also help as you can just get the first line.

 

Hope that helps. If all else fails, why not just check for that <?xml string first before parsing the links?

 

That Helped !!

 

Thanks alot !  ;D

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.