How can you display only news articles with a specific keyword, like "lol," in PHP?

To display only news articles with a specific keyword like "lol" in PHP, you can use a combination of PHP and SQL to query your database for articles containing the keyword. You can use the LIKE operator in your SQL query to search for the keyword in the article content or title. Once you retrieve the articles containing the keyword, you can display them on your webpage.

<?php
// Assuming you have a database connection established

$keyword = "lol";

$sql = "SELECT * FROM articles WHERE content LIKE '%{$keyword}%' OR title LIKE '%{$keyword}%'";
$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0) {
    while ($row = mysqli_fetch_assoc($result)) {
        echo "<h2>{$row['title']}</h2>";
        echo "<p>{$row['content']}</p>";
    }
} else {
    echo "No articles found with the keyword '{$keyword}'.";
}

mysqli_close($conn);
?>