random item from variable in array
Posted: Fri Dec 09, 2005 7:08 am
OK...I'm still building the same thing I've been banging on about on here for weeks now, and I have another problem.
(It is on an IIS server using Integrated Windows Authentication so I can't show anyone unfortunately).
Anyway, I have previously been using that random image script - you know the one, where there is a folder of images for it to select from -
but now I want to randomise the image using a variable from a flat file.
But it ain't working.
The script I am using is -
It just prints to screen.
Any clues....
(It is on an IIS server using Integrated Windows Authentication so I can't show anyone unfortunately).
Anyway, I have previously been using that random image script - you know the one, where there is a folder of images for it to select from -
but now I want to randomise the image using a variable from a flat file.
But it ain't working.
The script I am using is -
Code: Select all
<?php
srand ((double) microtime() * 1000000);
$randomquote = rand(0,count($pieces[5])-1);
$data = file('org/BLAH/news.txt');
$data = array_reverse($data);
foreach($data as $element) {
$element = trim($element);
$pieces = explode("¬", $element);
$pieces[4] = preg_replace('!\[url=(.+?)\](.+?)\[/url\]!Uim', '<a href="\1" target=\"_blank\">\2</a>', $pieces[4]);
$pieces[5] = preg_replace('!\[img\](.+?)\[/img\]!', '<img src="\1">',$pieces[5]);
echo $pieces[5][$randomquote];
}?>Code: Select all
< <Any clues....