Jump to content

Compatibility problem preg_match(); Windows - Linux


nemonline

Recommended Posts

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?

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!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.