Looking for simple php script

Hidden Gekko

3 Years and 100 Posts 0_o
I'm not new to working with php, but I couldn't make a script if my life depended on it...

I need a simply news-ticker like code for my web site, obviously written in php. It needs to be made so I can update the news myself, and so that 4-5 text items appear one at a time. Almost exactly like this... (not a scrolling marquee)

http://javascript.internet.com/games/flipper.html

But a php script so I can use the php include code to have it on all needed pages, while only having one file to change.

I bet it's pretty simple to make or easy to translate that javascript into php, or maybe there's already A premade script out there that one of you kind people could show me? I tried looking on hotscripts, but I really had no idea how to find what I want.

Much appreaciated for any help!
 
PHP is a server side scripting language. JavaScript is primarily a client side scripting language. You could use PHP to create JavaScript on your page so that it does what the example you gave does. With PHP, you could easily create a line of text that randomly changes each time you refresh the page. If you want it to change without refreshing the page, then you need JavaScript (or have a PHP script output javascript).

This would print a random line from a textfile called "news.txt" (must be readable by the script)
PHP:
<?

// get contents of the news file into a string
$filename = "news.txt";
$handle = fopen ($filename, "r");
$contents = fread ($handle, filesize($filename));
fclose($handle);

// Split the file into an array by unix lines
$news = explode("\n",$contents); 

// Print a random news entry
print $news[rand(0,count($news) - 1];

?>

Or you could have the PHP script output the last 5 entries of your text file to javascript:

PHP:
<?

// for the last 5 entries in the news.txt file
for($i=count($news) - 5;$i<count($news);$i++){
$counter++;

// print the JavaScript notices array
print 'notices['.$counter.'] = "'.$news[$i].'";'."\n";

}
?>
 
You could also check www.hotscripts.com for some scripts already made out there. They have PHP, ASP, CFM, Perl, CGI, Java, Python, etc...a nice variety. Each language is broken down into catagories. Some are pay scripts, some are free for noncommercial use, and some are GPL.
 
Back
Top