Re: pharse file random work with -n lines
| From: | Marek Kilimajer | Date: | Tue, 04 Mar 2003 17:24:52 +0000 |
| Subject: | Re: pharse file random work with -n lines | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-138140@lists.php.net to get a copy of this message | ||
I'm not sure what is wrong, you should add print_r function in different places to see if the variables really contain what they should.
WebDev wrote:
the last script gives me no error but it returns nothing on the page only empty ----- Original Message ----- From: Marek Kilimajer <kilimajer@webglobe.sk> To: WebDev <WebDev@browseabit.com> Sent: Tuesday, March 04, 2003 9:11 AM Subject: Re: [PHP] pharse file random work with -n lines$vier, $usern, $locst, $locstaa, $locc, $funf, $sech, $email, $Url, $ClassCat, $ClassCat2, $Headstart, $Headend, $Descrip, $End1, $Endzwei, $End3, $Endvier, $Endfunf, $Endsech, $Endsieben, $Endacht, $Endne, $dreizwei, $dreidrei, $dreivier, $dreifunf, $dreisechs ) = fgetcsv ($fp,50000,"\|") {You don't need to use fgets after the while loop (you are at the end of the file), $rand_array will contain your desired random rows: <?php $i = 0; $fp = fopen ("../../../../../home/httpd/html/Classifieds/data/ads.data", "r"); while($tmp= fgetcsv($fp,50000,"\|")) { $array[]=$tmp; } fclose ($fp); $rand_array=array_rand($array, 10); foreach($rand_array as $line) { list ($adnr, $user, $date, $listed, $hlong, $eins, $zwei, $drei,$vier,$usern, $locst, $locstaa, $locc, $funf, $sech, $email, $Url, $ClassCat, $ClassCat2, $Headstart, $Headend, $Descrip, $End1, $Endzwei, $End3, $Endvier, $Endfunf, $Endsech, $Endsieben, $Endacht, $Endne, $dreizwei, $dreidrei, $dreivier, $dreifunf, $dreisechs ) = $line; echo " <font face=\"Verdana\" size=\"1\"><ahref=\"http://www.browseabit.com/cgi-bin/Classifieds/classifieds.cgi?session_key=&search_and_display_db_button=on&db_id=$adnr&query=retrieval\" target=\"_blanko\">$Endzwei $End3</a><br></font>"; } ?> WebDev wrote:$vier,Parse error: parse error in /home/virtual/browse/home/httpd/html/Classifieds/infobox.php on line 9 <?php $i = 0; $fp = fopen ("../../../../../home/httpd/html/Classifieds/data/ads.data", "r"); while($tmp= fgetcsv($fp,50000,"\|")) { $array[]=$tmp; } $rand_array=array_rand($array, 10); $buffer = fgets($fp, 4096); list ($adnr, $user, $date, $listed, $hlong, $eins, $zwei, $drei,n$usern, $locst, $locstaa, $locc, $funf, $sech, $email, $Url, $ClassCat, $ClassCat2, $Headstart, $Headend, $Descrip, $End1, $Endzwei, $End3, $Endvier, $Endfunf, $Endsech, $Endsieben, $Endacht, $Endne, $dreizwei, $dreidrei, $dreivier, $dreifunf, $dreisechs ) = split ("\|", $buffer); echo " <font face=\"Verdana\" size=\"1\"><ahref=\"http://www.browseabit.com/cgi-bin/Classifieds/classifieds.cgi?sessioreturn_key=&search_and_display_db_button=on&db_id=$adnr&query=retrieval\" target=\"_blanko\">$Endzwei $End3</a><br></font>"; } fclose ($fp); ?> ----- Original Message ----- From: Marek Kilimajer <kilimajer@webglobe.sk> To: WebDev <WebDev@browseabit.com>; PHP <php-general@lists.php.net> Sent: Tuesday, March 04, 2003 8:25 AM Subject: Re: [PHP] pharse file random work with -n linesSorry, I forgot about the random part. Append the lines to an array, and then use array_rand: while($tmp= fgetcsv($fp,50000,"\|")) { $array[]=$tmp; } $rand_array=array_rand($array, 10); WebDev wrote:Yes it works here only this way "\|" but I have not figuered it toit random ----- Original Message ----- From: Marek Kilimajer <kilimajer@webglobe.sk> To: WebDev <WebDev@browseabit.com> Cc: <php-general@lists.php.net> Sent: Tuesday, March 04, 2003 5:00 AM Subject: Re: [PHP] pharse file random work with -n lineswhile(list ($adnr, $user, $date, $listed, $hlong, $eins, $zwei, $drei,
// here you can do what you need to do } are you sure you want "\|" and not "|"? WebDev wrote:
how can you return this randomized? how can I get every time I call this function a random set of lines ? Working Code to read 10 first lines and split the individual line
into
"r");("../../../../../public/httpd/html/datacontainer/data/storage.data",info careeners and do something with it ........ $i = 0; $fp = fopen
while (!feof ($fp) && $i < 10) { $i++; $buffer = fgets($fp, 4096); list ($adnr, $user, $date, $listed, $hlong, $eins, $zwei, $drei,
$vier, $usern, $locst, $locstaa, $locc, $funf, $sech, $email, $Url, $ClassCat, $ClassCat2, $Headstart, $Headend, $Descrip, $End1, $Endzwei, $End3, $Endvier, $Endfunf, $Endsech, $Endsieben, $Endacht, $Endne, $dreizwei, $dreidrei, $dreivier, $dreifunf, $dreisechs ) = split ("\|", $buffer);
\\ do something } fclose ($fp);