How can separating the bad word filtering logic into a separate file improve the readability and maintainability of PHP code?

Separating the bad word filtering logic into a separate file can improve the readability and maintainability of PHP code by encapsulating this specific functionality in its own module. This allows for better organization of code, easier debugging, and the ability to reuse the filtering logic in multiple parts of the application without duplicating code.

// bad_word_filter.php

function filterBadWords($input) {
    $badWords = ['bad', 'inappropriate', 'offensive'];
    
    foreach ($badWords as $word) {
        $input = str_ireplace($word, '***', $input);
    }
    
    return $input;
}
```

In the main PHP file:

```php
// main.php

include 'bad_word_filter.php';

$input = "This is a bad word.";
$filteredInput = filterBadWords($input);

echo $filteredInput;