0

I made a text file named ben.txt and there are some numbers line by line, for example 123456 so i want, whenever someone type !check 123456 so they should get message like Number Banned I Made a code But it doesn't working

My Code

$been = file_get_contents(ben.txt);
$isbanned = false;
foreach ($been as $bb) {
  if(strpos($message, "!sa $bb") ===0) $isbanned = true;
 sendMessage($chatId, "<b>Number Banned!</b>");
return;
}
John Conde
  • 217,595
  • 99
  • 455
  • 496
Wiker Bem
  • 29
  • 3
  • 1
    Does this answer your question? [PHP check if file contains a string](https://stackoverflow.com/questions/9059026/php-check-if-file-contains-a-string) – digijay May 20 '21 at 10:15

1 Answers1

1

You can turn the contents of the file into a regular expression that matches any of the strings.

$ex_cont = file("ben.txt", FILE_IGNORE_NEW_LINES);
$isbanned = false;
$regex = '/^!sa (' . implode('|', array_map('preg_quote', $ex_cont)) . ')/';
if (preg_match($regex, $message)) {
    $isbanned = true;
    sendMessage($chatId, "<b>Number Banned!</b>");
}
Barmar
  • 741,623
  • 53
  • 500
  • 612