PHP Loop through A – Z and Print CSS Style Declarations

Something silly that I’m going to keep. Loops through A-Z and prints some stylesheet declarations for me. Here’s the code:

<?php
 
foreach (range('a', 'z') as $i) {
//  echo "$i\n";
    echo "h1.icon_" . strtoupper($i) ." { background-image: url(images/alpha/" . $i . ".png); }\n";
}

It prints out styles (which we used to create Dropcaps for page titles):

h1.icon_A { background-image: url(images/alpha/a.png); }
h1.icon_B { background-image: url(images/alpha/b.png); }
h1.icon_C { background-image: url(images/alpha/c.png); }
h1.icon_D { background-image: url(images/alpha/d.png); }
h1.icon_E { background-image: url(images/alpha/e.png); }
h1.icon_F { background-image: url(images/alpha/f.png); }
h1.icon_G { background-image: url(images/alpha/g.png); }
h1.icon_H { background-image: url(images/alpha/h.png); }
h1.icon_I { background-image: url(images/alpha/i.png); }
h1.icon_J { background-image: url(images/alpha/j.png); }
h1.icon_K { background-image: url(images/alpha/k.png); }
h1.icon_L { background-image: url(images/alpha/l.png); }
h1.icon_M { background-image: url(images/alpha/m.png); }
h1.icon_N { background-image: url(images/alpha/n.png); }
h1.icon_O { background-image: url(images/alpha/o.png); }
h1.icon_P { background-image: url(images/alpha/p.png); }
h1.icon_Q { background-image: url(images/alpha/q.png); }
h1.icon_R { background-image: url(images/alpha/r.png); }
h1.icon_S { background-image: url(images/alpha/s.png); }
h1.icon_T { background-image: url(images/alpha/t.png); }
h1.icon_U { background-image: url(images/alpha/u.png); }
h1.icon_V { background-image: url(images/alpha/v.png); }
h1.icon_W { background-image: url(images/alpha/w.png); }
h1.icon_X { background-image: url(images/alpha/x.png); }
h1.icon_Y { background-image: url(images/alpha/y.png); }
h1.icon_Z { background-image: url(images/alpha/z.png); }

Post written by Ed Reckers

Founder and lead web development consultant at Red Bridge Internet : San Francisco WordPress Developers and Consultants.

Leave a Reply