|
|
|
|
Like this code?
Show the author your appreciation.
|
|
| |
This is my first post so i hope you like it.
The following selects 49 random feeds from an unlimited list and displays them on your website. It's Ideal for those moments when you got 5 minutes and dont know which one of your feeds to read. See it in action here : http://www.ozonew4m.com/random-webmaster-feeds.php
First of all lets pull all our rss urls from the text file and put them in an array
| <?php
$chars = "";
$chars = file('feedlist.txt');
?> | |
Next we create a nice little function that will jumble all our urls around inside the array and retrieve 49 random results in an array according to a paramaters we specify.
These are ($feedarray,$amounttoretrieve,randomkey)
| <?php
function random_subarray($ary, $len, $key) {
srand($key); shuffle($ary);
return array_slice($ary, 0, $len);
}
?> | |
now we use microtime to generate a random key for the function.
| <?php
srand((double)microtime()*1000000);
$code = rand(0,100);
?> | |
Now we have the data we need call the function.The following tells the function we want 49 results randomised using our random key. (NOTE: A static key will yeild static results)
| <?php
$fred = (random_subarray($chars, 49, $code));
?> | |
Now all we need to do is go through our array and display our reslts in a mystery graph so we can choose which one to read.
The following is optimised to display 7x7=49 results but you can display them how you wish.
| <?php
$rows = 7;
$count = 0;
echo "<h1> Random rss News </h1>";
echo "<h2>Select any of the boxes below to view a news feed</h2>";
echo "<p>The following table retrieves a selection of 49 feeds from a growing list and displays them randomly. </p>";
echo "<table width='100%'><tr><td align='center'><b>Enjoy the Feeds</b><table cellpadding='10'><tr>";
foreach ($fred as $key) {
$count++;
echo "<td><a href='rssfeed.php?feed=$key'><img src='mysteryfeed.jpg'width='25'height='25'style='border: 0;'alt='feed $count' /></a></td>";
if ($count % $rows == 0) {
if ($count != 49) {
print "</tr><tr>";
}
}
if ($count == 49) {
print "</tr>";
}
}
echo "</table><p><a href='feedslist.php'>View a complete list of feeds.</a><br /></p>";
echo "</td></tr></table>";
?> | |
If you download the zip file it also contains a page to display the feeds, a list off webmaster feeds, a page to display a full list of your feeds
|
|
| Tag content retrieval from websites with preg_match Categories : PHP, Regexps, Arrays, HTML and PHP | | | Array values from javascript to php Categories : PHP, Java Script, Arrays | | | clearing variables in php3 Categories : Variables, Arrays, PHP | | | RSS parser.
Parses RSS into an array. Quick and nasty but does the job.
No checking is done for correct Tags, only correct XML.
PHP4 needed to display result (uses print_r). Categories : PHP, XML, PHP Classes, Rich Site Summary (RSS) | | | Weighted Random - Random Scripts usually chose one out of each item, and each item have an equal chance to be chosen. But what if you want an item to be chosed more frequently than other? Categories : PHP, Math., Arrays | | | Display list of files within current and subdirectories (recursively) showing
each file as an anchored link and each directory as a category header. Categories : Filesystem, Directories, Arrays, PHP | | | PHP Dump in html format the contents of one array variable with a recursive list of the nested array variables inside. Categories : PHP, Arrays, Variables | | | Array Insertion Categories : PHP, PHP Classes, Arrays | | | Check for functional file links (broken Files)
Categories : PHP, Data Validation, FTP, Regexps, Arrays | | | This gets the http response headers for a given url and returns them in an assoc array. i.e. to test if a url exists: $array = get_http_headers($url); if($array[result]=200) { } Categories : HTTP, Arrays, PHP | | | Beginners Array Functions Categories : PHP, Beginner Guides, Arrays | | | Dump the contents of a PHP variable in html format with a recursive list of subfolders and files from a given root directory.
Categories : PHP, Directories, Variables, Arrays | | | How to pass an array from one PHP Script to another via an HTML form Categories : PHP, HTML and PHP, Arrays | | | How to load a query result into a PHP Array Categories : PHP, Databases, Arrays, MySQL | | | dynamic table columns Categories : PHP, HTML and PHP, Arrays, Databases, MySQL | |
|
|
|