Hey
I got this PHP script, wich generates a javascript array,
<?
//PHP SCRIPT: getimages.php
//Header("content-type: application/x-javascript");
//This function gets the file names of all images in the current directory
//and ouputs them as a JavaScript array
function returnimages($dirname="img/gallery/") {
$pattern="(\\.jpg$)|(\\.png$)|(\\.jpeg$)|(\\.gif$)"; //valid image extensions
$files = array();
$curimage=0;
if($handle = opendir($dirname)) {
while(false !== ($file = readdir($handle))){
if(eregi($pattern, $file)){ //if this file is a valid image
//Output it as a JavaScript array element
echo 'fadeimagesPHP['.$curimage.']=["'.$dirname.$file.'"];'."\
";
$curimage++;
}
}
closedir($handle);
}
return($files);
}
echo 'var fadeimagesPHP=new Array();'."\
"; //Define array in JavaScript
returnimages() //Output the array elements containing the image file names
/* THE Array should look like this
var fadeimagesPHP=new Array()
fadeimagesPHP[0]=["img/gallery/01_2.jpg"]
fadeimagesPHP[1]=["img/gallery/02_2.jpg"]
fadeimagesPHP[2]=["img/gallery/03_2.jpg"]
*/
?>
It’s not mine, i found it on web:
http://www.javascriptkit.com/javatutors/externalphp2.shtml
What I’m doing now is calling PHP in my main page, with Require once.
But I want it to generate the code directly to the *.js file.
How could this be done? JSON?
If you have time to answer me, please do.
Thank you