How to grab from dati.txt file random links (example 500 links take out 5)

Heigueinces

New Member
I want to show on first page randomly selected links from a dati.txt file (from about 1000 links 5 randomly selected) from this:\[code\]<?php$righe_msg = file("dati.txt");$numero=0;foreach($righe_msg as $riga){ $dato = explode("|", trim($riga)); if (trim($dato[5])=="yes") { $numero++; echo"<tr><td bgcolor='#EEEEEE'>&raquo; <a href='http://stackoverflow.com/questions/10552218/$dato[2]'> $dato[1]</a></td></tr> "; }}?> \[/code\]About dati.txtdati.txt is made like this\[code\]date1.. |title1..|link1...|description1|email1|yesdate2.. |title2..|link2...|description2|email2|yesdate3.. |title3..|link3...|description3|email3|yesdate4.. |title4..|link4...|description4|email4|yesdate5.. |title5..|link5...|description5|email5|yesdate6.. |title6..|link6...|description6|email6|yes..\[/code\]But how do you get for example (links) out with this code:\[code\]$links = file("dati.txt");$numLinks = count($links);$tmp = array();for ($i = 0; $i < min(5, $numLinks); $i++){ $randomIndex = rand(0, $numLinks - 1); $randomLink = $links[$randomIndex]; // Avoid duplicates: if (in_array($randomLink, $tmp)) { $i--; continue; } $tmp[] = $randomLink; echo $randomLink;}\[/code\]Thanks
 
Back
Top