How to grab from dati.txt file random links (example 500 links take out 5)
<p>I want to show on first page randomly selected links from a dati.txt file (from about 1000 links 5 randomly selected) from this:</p>

<pre><code>&lt;?php

$righe_msg = file("dati.txt");

$numero=0;
foreach($righe_msg as $riga)
{
    $dato = explode("|", trim($riga));

    if (trim($dato[5])=="yes")
    {
        $numero++;
        echo"&lt;tr&gt;&lt;td bgcolor='#EEEEEE'&gt;&amp;raquo; &lt;a href='$dato[2]'&gt; $dato[1]&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt; ";
    }
}

?&gt; 
</code></pre>

<p>About dati.txt
dati.txt is made like this</p>

<pre><code>date1.. |title1..|link1...|description1|email1|yes
date2.. |title2..|link2...|description2|email2|yes
date3.. |title3..|link3...|description3|email3|yes
date4.. |title4..|link4...|description4|email4|yes
date5.. |title5..|link5...|description5|email5|yes
date6.. |title6..|link6...|description6|email6|yes
..
</code></pre>

<p>But how do you get for example (links) out with this code:</p>

<pre><code>$links = file("dati.txt");
$numLinks = count($links);
$tmp = array();
for ($i = 0; $i &lt; 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></pre>

<p>Thanks</p>
