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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nemonline
Forum Newbie
Posts: 2
Joined: Fri Mar 23, 2012 6:18 am

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

Post 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?
Last edited by nemonline on Mon Apr 02, 2012 2:00 am, edited 1 time in total.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Compatibility problem preg_match(); Windows - Linux

Post by Celauran »

User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Compatibility problem preg_match(); Windows - Linux

Post by requinix »

Try glob and json_encode.
Post Reply