i already made a search of news script but i didnt get any thing about that i found a bbc script once when i even dont know about codings but now i had format the pc several times and cant remember wheres the script from if you any one know about bbc news script for wap let me know
need bbc news script
Collapse
X
-
u are really to lazy to use Google
Added after 13 minutes:
1. Displaying an external RSS feed as HTML
The PHP class presented in the preceding article also includes a display option, but usually you will want to customise that for your website. In this case we use the 'raw' data to present a list of headlines and dates.
We're using BBC News for this example simply because they have some of the friendliest Terms of Use. Before including any external feeds on your website, always check the relevant Terms of Use to make sure that you're allowed to display their content.
2. PHP code for this example
Again, this is just an example of what you can do using our PHP classes (there's also code for an Atom Feed Reader) to include external feeds.
The parameters at the top define the feed source, how many items to display and where and for how long to keep a local cached version of the data.
After that it's just a matter of extracting the relevant data from the array returned by getRawOutput() and adding some simple HTML formatting.
Code:<?PHP # define script parameters $BLOGURL = "http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/front_page/rss.xml"; $NUMITEMS = 2; $TIMEFORMAT = "j F Y, g:ia"; $CACHEFILE = "/tmp/" . md5($BLOGURL); $CACHETIME = 4; # hours # download the feed iff a cached version is missing or too old if(!file_exists($CACHEFILE) || ((time() - filemtime($CACHEFILE)) > 3600 * $CACHETIME)) { if($feed_contents = @file_get_contents($BLOGURL)) { # write feed contents to cache file $fp = fopen($CACHEFILE, 'w'); fwrite($fp, $feed_contents); fclose($fp); } } include "class.myrssparser.php"; $rss_parser = new myRSSParser($CACHEFILE); # read feed data from cache file $feeddata = $rss_parser->getRawOutput(); extract($feeddata['RSS']['CHANNEL'][0], EXTR_PREFIX_ALL, 'rss'); # display leading image if(isset($rss_IMAGE[0]) && $rss_IMAGE[0]) { extract($rss_IMAGE[0], EXTR_PREFIX_ALL, 'img'); echo "<p><a title=\"{$img_TITLE}\" href=\"{$img_LINK}\"><img src=\"{$img_URL}\" alt=\"\"></a></p>\n"; } # display feed title echo "<h4><a title=\"",htmlspecialchars($rss_DESCRIPTION),"\" href=\"{$rss_LINK}\" target=\"_blank\">"; echo htmlspecialchars($rss_TITLE); echo "</a></h4>\n"; # display feed items $count = 0; foreach($rss_ITEM as $itemdata) { echo "<p><b><a href=\"{$itemdata['LINK']}\" target=\"_blank\">"; echo htmlspecialchars(stripslashes($itemdata['TITLE'])); echo "</a></b><br>\n"; echo htmlspecialchars(stripslashes($itemdata['DESCRIPTION'])),"<br>\n"; echo "<i>",date($TIMEFORMAT, strtotime($itemdata['PUBDATE'])),"</i></p>\n\n"; if(++$count >= $NUMITEMS) break; } # display copyright information echo "<p><small>© {",htmlspecialchars($rss_COPYRIGHT),"}</small></p>\n"; ?>
Please Note: this code is provided for explanatory purposes only and care should be taken when using or modifying it for any other purpose.
3. myRSSParser: Could not open $file for input
This code assumes that the script has permission to create files in the /tmp/ directory and that those files will remain there, readable, for a number of hours. This is so that the RSS feed doesn't have to be fetched again every time the page is loaded, but rather the relevant data can be stored on the server.
If the /tmp/ directory does not exist, is not writable or is not keeping files in place for sufficient time then you will need to create your own webserver-writable directory and change the $CACHEFILE setting accordingly.
To see the actual error message from the server, you will need to change this line in the class file:
Code:$fp = @fopen($file, 'r') or die("myRSSParser: Could not open $file for input");
Code:$fp = fopen($file, 'r');
4. Analyzing the Feed data
Using different feed sources can be tricky as they can use different RSS formats which means different tagnames and data formats. The first step then is to examine the 'raw' data to see what tags are available and how they are nested.
Code:<pre><?PHP print_r($feeddata); ?></pre>
Code:Array ( [TITLE] => BBC News - Home [LINK] => http://www.bbc.co.uk/go/rss/int/news/-/news/ [DESCRIPTION] => The latest stories from the Home section of the BBC News web site. [LANGUAGE] => en-gb [LASTBUILDDATE] => Sat, 31 Jul 2010 11:00:46 +0000 [COPYRIGHT] => Copyright: (C) British Broadcasting Corporation, see http://news.bbc.co.uk/2/hi/help/rss/4498287.stm for terms and conditions of reuse. [DOCS] => http://www.bbc.co.uk/syndication/ [TTL] => 15 [ITEM] => Array ( [0] => Array ( [TITLE] => 'Progress' in new Afghan mission [DESCRIPTION] => British forces say they have seized two compounds in a Taliban stronghold at the start of a fresh bid to push insurgents out of Helmand province. [LINK] => http://www.bbc.co.uk/go/rss/int/news/-/news/uk-10825573 [GUID] => http://www.bbc.co.uk/news/uk-10825573 [PUBDATE] => Sat, 31 Jul 2010 07:47:38 +0000 ) [1] => Array ( [TITLE] => Love Parade memorial service held [DESCRIPTION] => Germany holds an emotional memorial service for the 21 people killed in a stampede at the Love Parade dance festival a week ago. [LINK] => http://www.bbc.co.uk/go/rss/int/news/-/news/world-europe-10825599 [GUID] => http://www.bbc.co.uk/news/world-europe-10825599 [PUBDATE] => Sat, 31 Jul 2010 09:54:22 +0000 ) ) )
5. Possible improvements
One drawback of the above script is that every $CACHETIME hours one visitor to the page displaying the RSS feed will have the page load delayed as the feed is updated.
This could be avoided if there was a CRON job (scheduled server side script) updating the $CACHEFILE at regular intervals so you don't have to rely on the PHP script to perform that function.
If that's not an option you can also modify the script so that the fetching of the feed happens at the end of the page rather than in the middle.
To achieve that, we take the section of the code that updates the feed and turn it into a PHP function:
Code:function updateFeed() { global $BLOGURL, $CACHEFILE; if($feed_contents = file_get_contents($BLOGURL)) { # write feed contents to cache file $fp = fopen($CACHEFILE, 'w'); fwrite($fp, $feed_contents); fclose($fp); } }
Code:# download the feed iff cached version is missing if(!file_exists($CACHEFILE)) updateFeed();
Code:<?PHP # download the feed iff cached version is too old if((time() - filemtime($CACHEFILE)) > 3600 * $CACHETIME) { flush(); updateFeed(); } ?>
Last edited by riderz; 31.07.10, 14:05.________________
Jacques
jacques@gw-designs.co.za
http://coding.biz.tm
Come join and lets make it a place to learn all the noobies how to code
__________________
NEVER FORGET TO CLICK THE TANX BUTTON IF U LIKE WHAT IM SHARING OR HELPING WITH
Comment