You could wrap the code I linked to, into a function, and save it as a separate PHP script.
adrotater.php
<?php
function adrotater($filename) {
$fcontents = join ('', file ($filename));
$s_con = split("~",$fcontents);
$banner_no = rand(0,(count($s_con)-1));
echo $s_con[$banner_no];
}
?>
Place the above file, adrotater.php, in the same directory as your other scripts. This would allow you to use the function, in your main PHP file, like so:
index.php
<?php
// Include the separate PHP script
include('adrotater.php');
//
// Blah blah blah, some code here
//
// Display a random advertisement from banner_ads.txt
adrotater('banner_ads.txt');
//
// More code here
//
?>
Make sure to include the adrotater.php file in every file you want to use the adrotater function.
Then the argument passed to it,
'banner_ads.txt', is the text file with the advertisements inside.