Note that there are some explanatory texts on larger screens.

plurals
  1. POEcho php array value
    primarykey
    data
    text
    <p>I have the following code that reads the content of a folder</p> <p>PHP Code:</p> <pre><code>&lt;? //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="./images") { $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 'galleryarray['.$curimage.']="'.$file .'";' . "\n"; $curimage++; } } closedir($handle); } sort($files); return($files); } echo 'var galleryarray=new Array();' . "\n"; //Define array in JavaScript returnimages() //Output the array elements containing the image file names ?&gt; </code></pre> <p>which spits out this the following code:</p> <pre><code>var galleryarray = new Array(); galleryarray[0] = "image1.jpg"; galleryarray[1] = "image5.jpg"; galleryarray[2] = "image2.jpg"; galleryarray[3] = "image4.jpg"; galleryarray[4] = "image8.jpg"; galleryarray[5] = "image7.jpg"; galleryarray[6] = "image0.jpg"; galleryarray[7] = "image3.jpg"; galleryarray[8] = "image6.jpg";​ </code></pre> <p>Now in my html file I want to echo something like </p> <pre><code>&lt;img src="images/image0.jpg" /&gt; &lt;img src="images/image1.jpg"/&gt; ... ... </code></pre> <p>How can I do that?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload