Replace unwanted words with preferred alternatives.
Result = Oi mate, Im gonna kick your bottom on COD!
PHP
<?php
declare(strict_types=1);
/**
*
* Features:
* - Case-insensitive matching
* - Easy to extend (just edit the $replacements array)
* - Safe for any input (typed and validated)
*/
function cleanText(string $text): string
{
$replacements = [
'asshole' => 'mate',
'arse' => 'bottom',
];
return str_ireplace(
array_keys($replacements),
array_values($replacements),
$text
);
}
// Example
$original = "Oi asshole, Im gonna kick your arse on COD!";
$cleaned = cleanText($original);
echo $cleaned;Result = Oi mate, Im gonna kick your bottom on COD!
Article discussion
Share your thoughts about this article.
Log in or create an account to comment.
No comments yet. Be the first to join the discussion.