areyouready344
asked on
how to unsort output text lines from a sorted input in php?
The following code below reads sorted text lines from a file, around 30 lines and output them in sorted lines on the computer screen. But what I would like is to output the input sorted text lines unsorted without repeating the same text lines..
while(!feof($file))
{
$myfilevalue = fgets($file);
echo '<font size="6" color="' . random_color() . '">' . $myfilevalue . '</font>';
}
function random_color()
{
mt_srand((double)microtime ()*1000000 );
$c = '';
while(strlen($c)<6)
{
$c .= sprintf("%02X", mt_rand(0, 255));
}
return $c;
}
fclose($file);
?>
</body>
</html>
while(!feof($file))
{
$myfilevalue = fgets($file);
echo '<font size="6" color="' . random_color() . '">' . $myfilevalue . '</font>';
}
function random_color()
{
mt_srand((double)microtime
$c = '';
while(strlen($c)<6)
{
$c .= sprintf("%02X", mt_rand(0, 255));
}
return $c;
}
fclose($file);
?>
</body>
</html>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Awesome! Thanks for points.
Cheers
Cheers
ASKER
$display_ten_lines = 10;
$count_0 = 0;
while(!feof($file))
{
$myfilevalue[] = fgets($file);
}
if (shuffle($myfileValue)){
foreach ($myfileValue as $v){
if($count_0 < $display_ten_lines)
{
echo '<font size="6" color="' . random_color() . '">' . $v . '</font>';
$count_0++
}
}
}