How can PHP be used to automatically remove forum-inappropriate content from links shared by users?

To automatically remove forum-inappropriate content from links shared by users, we can use PHP to create a script that checks the content of the shared link against a list of inappropriate keywords or patterns. If any inappropriate content is detected, the script can filter out the link before displaying it on the forum.

<?php

// List of inappropriate keywords or patterns
$inappropriate_words = array("keyword1", "keyword2", "pattern1");

// Function to check if link contains inappropriate content
function checkLink($link, $inappropriate_words) {
    foreach ($inappropriate_words as $word) {
        if (stripos($link, $word) !== false) {
            return false;
        }
    }
    return true;
}

// Example link shared by user
$user_link = "http://example.com/inappropriate-link";

// Check if link contains inappropriate content
if (checkLink($user_link, $inappropriate_words)) {
    echo "Link is appropriate: " . $user_link;
} else {
    echo "Link contains inappropriate content and has been filtered.";
}
?>