jam Posted June 29, 2007 Report Share Posted June 29, 2007 Man ir šāds skripts, kas nolasa diru ar gif un jpg failiem. Aiz katra pilnā faila ceļa man vajag ielikt komtu, izņemot, ja tas ir pēdējais nolasītais fails: $dir = opendir ("img_dira"); while (false !== ($file = readdir($dir))) { if (strpos($file, '.gif',1)||strpos($file, '.jpg',1) ) { echo "'/img_dira/".$file."'"; if(navpedejaisfails){ echo ","; } } } closedir($dir); Kā to izdarīt? Link to comment Share on other sites More sharing options...
Grey_Wolf Posted June 29, 2007 Report Share Posted June 29, 2007 liec komatu sakumaa iznjemot 1 elementam Apmeram shadi --> neparbaudiju bet vajadzeetu straadat if(isset($mainigais)) { $komats=''; } else { $komats=','; } $mainigais=true; // LAI VAIRAAK NEIZMANTOTU //un kad izvadi tos failus tad echo $komats.$fails; Link to comment Share on other sites More sharing options...
andrisp Posted June 29, 2007 Report Share Posted June 29, 2007 (edited) <?php $dir = opendir ("img_dira"); $imgs = array(); while (false !== ($file = readdir($dir))) { if (strpos($file, '.gif', 1) || strpos($file, '.jpg', 1) ) { $imgs[] = "'/img_dira/".$file."'"; } } echo implode(", ", $imgs); closedir($dir); ?> PS. Tu saproti, kas viņš izdrukās arī bla.gif.php failus ? PS2. Tev pašam nekaitina, ka kods ir haotisks un grūti izsekojams ? PS3. Dari šitā labāk: if (strtolower(substr('blabla.gif', -4, 4)) == '.gif') {} Edited June 29, 2007 by andrisp Link to comment Share on other sites More sharing options...
jam Posted June 29, 2007 Author Report Share Posted June 29, 2007 Andrisp, tu esi mans pēdējo dienu varonis :) Link to comment Share on other sites More sharing options...
blackhalt Posted June 29, 2007 Report Share Posted June 29, 2007 <?php $a=glob('img_dira/{*.jpg,*.gif}',GLOB_BRACE); $b=count($a)-1; foreach($a as $cik => $ko){ if($cik==$b){ echo '/'.$ko; }else{ echo '/'.$ko.','; } } ?> Link to comment Share on other sites More sharing options...
andrisp Posted June 29, 2007 Report Share Posted June 29, 2007 Viltīgs risinājums. Link to comment Share on other sites More sharing options...
Recommended Posts