What are the potential pitfalls of using background images for rollover effects in PHP?

Using background images for rollover effects in PHP can lead to slower loading times and increased server load, as each rollover effect requires a separate HTTP request to fetch the image. To solve this issue, consider using CSS sprites instead, which combine multiple images into a single file and reduce the number of HTTP requests needed.

<?php
// Example of using CSS sprites for rollover effects
echo '<style>';
echo '.button {';
echo 'background-image: url("sprites.png");';
echo 'background-position: 0 0;';
echo '}';
echo '.button:hover {';
echo 'background-position: -50px 0;';
echo '}';
echo '</style>';
echo '<button class="button">Hover over me</button>';
?>