What are common pitfalls when trying to include CSS parameters in JavaScript alerts using PHP variables?

When trying to include CSS parameters in JavaScript alerts using PHP variables, a common pitfall is not properly escaping the PHP variables or not concatenating them correctly within the JavaScript alert function. To solve this issue, you can use the `json_encode()` function to properly escape the PHP variables and concatenate them within the JavaScript alert function.

<?php
$color = 'red';
$message = 'Error message';

echo '<script>';
echo 'alert(' . json_encode('<div style="color: ' . $color . '">' . $message . '</div>') . ');';
echo '</script>';
?>