- substr: documentation ( source)
- similar_text: documentation ( source)
- preg_match: documentation ( source)
<?php
function isSpam($comment) {
// Pattern to match common phrases and links
$pattern = '/(Like or Not\?|Check:)\s*(https?:\/\/[^\s]+)/i';
// Check if the pattern matches
if (preg_match($pattern, $comment)) {
return true;
}
// Known spam phrases (can be expanded)
$knownSpam = [
"Like or Not? Check:",
];
// Calculate similarity with known spam phrases
foreach ($knownSpam as $spam) {
if (similar_text($spam, substr($comment, 0, strlen($spam))) / strlen($spam) > 0.8) {
return true;
}
}
return false;
}
echo isSpam('like or not');