Exercise : Kitties (by Alex Miller; revised by Morgan Doocy)

There are several kitties whose breeds are listed in a file called kitties.txt. Write the PHP code to output an image of each breed. Images are .jpg files in the kitties folder (ZIP archive), and their filenames are lowercase breed names with any spaces replaced by underscores: scottish_fold.jpg, etc.  Include an alt attribute for each image, using the full original breed name: "a Scottish Fold kittie!", etc.  Assume the kitties folder is inside the current directory.

a Bengal kittie! a Birman kittie! a Chausie kittie! a Manx kittie! a Persian kittie! a Ragdoll kittie! a Savannah kittie! a Scottish Fold kittie! a Siamese kittie! a Snowshoe kittie!

Exercise solution

$breeds = file('kitties.txt', FILE_IGNORE_NEW_LINES);
foreach ($breeds as $breed) {
	$filename = str_replace(' ', '_', strtolower($breed));
	?>
	<img src="kitties/<?= $filename ?>.jpg" alt="a <?= $breed ?> kittie!" />
	<?php
}