nemonline Posted March 23, 2012 Share Posted March 23, 2012 Hi, I have the following code: <? Header("content-type: application/x-javascript"); function returnimages($dirname="./windows/prezentare_jpg/") { $files = array(); $curimage=0; if($handle = opendir($dirname)) { while(false !== ($file = readdir($handle))){ if(preg_match('/.jpg$/i', $file)){ echo 'galleryarray['.$curimage.']="'.$file .'";'; $curimage++; } } closedir($handle); } return($files); } echo 'var galleryarray=new Array();'; returnimages(); ?> Ran on windows (xampp 1.7.7, PHP 5.3.8, Apache 2.2.21) it returns the correct alfabetical/numerical order: var galleryarray=new Array();galleryarray[0]="01.jpg";galleryarray[1]="02.jpg";galleryarray[2]="03.jpg";galleryarray[3]="04.jpg";galleryarray[4]="05.jpg";galleryarray[5]="06.jpg";galleryarray[6]="07.jpg";galleryarray[7]="08.jpg";galleryarray[8]="09.jpg";galleryarray[9]="10.jpg";galleryarray[10]="11.jpg";galleryarray[11]="12.jpg"; Ran on linux (PHP 5.3.8, Apache 2.2.21) it returns an incorrect order: var galleryarray=new Array();galleryarray[0]="06.jpg";galleryarray[1]="01.jpg";galleryarray[2]="08.jpg";galleryarray[3]="10.jpg";galleryarray[4]="04.jpg";galleryarray[5]="11.jpg";galleryarray[6]="05.jpg";galleryarray[7]="03.jpg";galleryarray[8]="07.jpg";galleryarray[9]="09.jpg";galleryarray[10]="02.jpg";galleryarray[11]="12.jpg"; I need the script to run correctly on the linux server. What could be the problem? What can i try? Link to comment https://forums.phpfreaks.com/topic/259550-compatibility-problem-preg_match-windows-linux/ Share on other sites More sharing options...
trq Posted March 23, 2012 Share Posted March 23, 2012 Either way your doing too much work here. See glob. Link to comment https://forums.phpfreaks.com/topic/259550-compatibility-problem-preg_match-windows-linux/#findComment-1330450 Share on other sites More sharing options...
nemonline Posted March 23, 2012 Author Share Posted March 23, 2012 Problem Solved! <?php // long open tags header("Content-Type: text/javascript"); // the right MIME type echo "var galleryarray = ", json_encode(glob("./windows/prezentare_jpg/*.jpg")), ";"; // and that's it. two lines ?> Thank you! Link to comment https://forums.phpfreaks.com/topic/259550-compatibility-problem-preg_match-windows-linux/#findComment-1330486 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.