Is it recommended to centralize bad word detection in a separate file when working with multiple scripts in PHP?

When working with multiple scripts in PHP, it is recommended to centralize bad word detection in a separate file to promote code reusability and maintainability. By separating this functionality into its own file, you can easily include it in multiple scripts without duplicating code. This approach also allows for easier updates and modifications to the bad word detection logic.

// badWordDetection.php

function detectBadWords($text) {
    $badWords = ['bad', 'inappropriate', 'offensive']; // Define your list of bad words here
    foreach($badWords as $badWord) {
        if (stripos($text, $badWord) !== false) {
            return true;
        }
    }
    return false;
}
```

In your main script, you can include the `badWordDetection.php` file and use the `detectBadWords()` function to check for bad words in a given text:

```php
<?php
include 'badWordDetection.php';

$text = "This is a sample text with a bad word.";
if (detectBadWords($text)) {
    echo "Bad words detected!";
} else {
    echo "No bad words found.";
}
?>