
PHP; read picture folders, sort them into sets and output them with a loop - cemfirat
how can i do it ever &lt;img&gt; takes the right picture sets<p>here the picture directory (img):<p>- example_start.jpg
 - example-A_small.jpg
 - example-A_small_2x.jpg
 - example-A_medium.jpg
 - example-A_medium_2x.jpg
 - example-A_large.jpg
 - example-A_large_2x.jpg
 - example-AB_small.jpg
 - example-AB_small_2x.jpg
 - example-AB_medium.jpg
 - example-AB_medium_2x.jpg
 - example-AB_large.jpg
 - example-AB_large_2x.jpg<p>&#x2F;&#x2F; Get Pictures
$imgDir = &#x27;img&#x27;;
$imgs = glob($imgDir.&#x27;&#x2F;<i>{[!_start</i>].jpg}&#x27;, GLOB_BRACE); &#x2F;&#x2F; without _start image!
asort($imgs);<p>caption.php file:<p>$imgCaption = array(&#x27;example-A is nice&#x27;,&#x27;example-B is blue&#x27;);<p>require_once &#x27;caption.php&#x27;; &#x2F;&#x2F; picture caption data
 foreach($imgs as $files =&gt; $img){
  if(!isset($imgCaption[$files])){$imgCaption[$files] = &#x27;&#x27;;}
echo&#x27;
  &lt;img
   src=&quot;&#x27;.$_SERVER[&#x27;REQUEST_URI&#x27;].$img.&#x27;&quot;
   srcset=&quot;
   &#x27;.$_SERVER[&#x27;REQUEST_URI&#x27;].$img.&#x27; 734w,
   &#x27;.$_SERVER[&#x27;REQUEST_URI&#x27;].$img.&#x27; 1472w,
   &#x27;.$_SERVER[&#x27;REQUEST_URI&#x27;].$img.&#x27; 1068w,
   &#x27;.$_SERVER[&#x27;REQUEST_URI&#x27;].$img.&#x27; 2136w,
   &#x27;.$_SERVER[&#x27;REQUEST_URI&#x27;].$img.&#x27; 2016w,
   &#x27;.$_SERVER[&#x27;REQUEST_URI&#x27;].$img.&#x27; 4032w,&quot; 
   sizes=&quot;(min-width: 640px) 50vw, 100vw&quot; width=&quot;100%&quot; height=&quot;100%&quot;   
   alt=&quot;&#x27;.$imgCaption[$files].&#x27;&quot;&gt;
&#x27;;<p>expected Output<p>&lt;img
  src=&quot;img&#x2F;example_A-small.jpg&quot;
  srcset=&quot;
  img&#x2F;example-A_small.jpg 734w,
  img&#x2F;example-A_small_2x.jpg 1472w,
  img&#x2F;example-A_medium.jpg 1068w,
  img&#x2F;example-A_medium_2x.jpg 2136w,
  img&#x2F;example-A_large.jpg 2016w,
  img&#x2F;example-A_large_2x.jpg 4032w,&quot; 
  sizes=&quot;(min-width: 640px) 50vw, 100vw&quot; width=&quot;100%&quot; height=&quot;100%&quot; alt=&quot;Example A&quot;&gt;
&lt;img
  src=&quot;img&#x2F;example_B-small.jpg&quot;
  srcset=&quot;
  img&#x2F;example-AB_small.jpg 734w,
  img&#x2F;example-AB_small_2x.jpg 1472w,
  img&#x2F;example-AB_medium.jpg 1068w,
  img&#x2F;example-AB_medium_2x.jpg 2136w,
  img&#x2F;example-AB_large.jpg 2016w,
  img&#x2F;example-AB_large_2x.jpg 4032w,&quot; 
  sizes=&quot;(min-width: 640px) 50vw, 100vw&quot; width=&quot;100%&quot; height=&quot;100%&quot; alt=&quot;Example A&quot;&gt;
======
bernierocks
This isn't stackoverflow. Get someone else to do your homework.

