00:00
00:00
Newgrounds Background Image Theme

Xyphondevi just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

PHP, randomly pulling from array

675 Views | 0 Replies
New Topic Respond to this Topic

PHP, randomly pulling from array 2014-05-14 12:09:18


Ok, so to put it shortly I have alot HTML pages generated on my website. In order to search through them I index it all to a txt file, and pull them according to words accociated with each link. I'm trying to randomly pull content, but my logic is flawed. I'm not so much asking as how to code it as how to go about it. I have this script, which does pull randomly but only from about the first 40 rows in the file and only pulls 3 and makes duplicate links in the random menu (there's supposed to be 10 random links:)

<?php
    
        $filename = $_SERVER['DOCUMENT_ROOT'] . "/search/search.index.dat";
        $file = fopen($filename, "r+");
        $stream = fread($file, filesize($filename));
        fclose( $file );
        
         $search[0] = explode( "\n", $stream );
        $tmp_ind = rand(0, sizeOf($stream));
        for( $i = 0; $i < 10; $i++ )
        {
        
            foreach( $index as $key => $content )
            {

                $j=0;
                foreach( $index as $name => $value )
                {
                
                    if($content==$value)
                    {
                    
                        $value = rand(0, sizeOf($stream));
                    
                    }
                
                }
            
                if( $content == $tmp_ind )
                {
                
                    $tmp_ind = rand(0, sizeOf($stream));
                
                }
            
            }
            $index[$i] = $tmp_ind;

            $search[1] = explode( "|", $search[0][$tmp_ind] );
            $search[2] = str_replace($_SERVER['DOCUMENT_ROOT'],$_SERVER['HTTP_HOST'],$search[1][0]);
            $search[3] = str_replace($_SERVER['DOCUMENT_ROOT'],"",$search[2]);


            $search[4] = get_meta_tags("http://".$search[2]);
            print "<li><a href=\"".$search[1][0]."\">".$search[4]["search"]."</a></li>\n<br />\n";
            
        }
        
    ?>

P.S. the text file rows look like this:

doc/root/file/index.html|website|content

doc/root/file/books.html|book1|author|etc

and just to be more clear each file has a meta tag with its title in it, and thats how i'm pulling them