Page 1 of 1

[SOLVED]Compatibility problem preg_match(); Windows - Linux

Posted: Fri Mar 23, 2012 6:22 am
by nemonline
Hi,

I have the following code:

Code: Select all


<? 
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:

Code: Select all

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:

Code: Select all


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?

Re: Compatibility problem preg_match(); Windows - Linux

Posted: Fri Mar 23, 2012 7:03 am
by Celauran

Re: Compatibility problem preg_match(); Windows - Linux

Posted: Fri Mar 23, 2012 7:19 am
by requinix
Try glob and json_encode.