How can CSS classes be used effectively in PHP to style text based on specific keywords from a database?

To style text based on specific keywords from a database in PHP, you can use CSS classes to apply different styles to the text based on the keywords. First, retrieve the text from the database and then use PHP to check for the presence of keywords. If a keyword is found, add a specific CSS class to the text element. Finally, define the CSS classes in your stylesheet to apply the desired styling.

<?php
// Retrieve text from the database
$text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.";

// Define an array of keywords to style
$keywords = array("Lorem", "amet");

// Loop through the keywords and apply CSS classes to the text
foreach($keywords as $keyword) {
    if(strpos($text, $keyword) !== false) {
        $text = str_replace($keyword, "<span class='highlight'>$keyword</span>", $text);
    }
}

// Output the styled text
echo "<p>$text</p>";
?>
```

```css
.highlight {
    color: red;
    font-weight: bold;
}