phpnumberseregi

eregi or preg from txt file in php


I have website selling charge cards, I use this code for selling to customers they verify the mobile number, manually (add a line every time) recently I use SMS service and numbers stored in text file in the site, how can remove these lines, and I get the numbers from the .txt files? (the numbers stored line by line in txt file)

if ($data[mobile] AND !eregi("^09512362982$", $data[mobile]))
if ($data[mobile] AND !eregi("^09527415120$", $data[mobile]))
if ($data[mobile] AND !eregi("^09532247462$", $data[mobile]))
if ($data[mobile] AND !eregi("^09535241919$", $data[mobile]))
if ($data[mobile] AND !eregi("^09535716327$", $data[mobile]))
$error .= "Mobile number not valid, please verify your number<br />";

Solution

  • You can use file to read the contents of your text file into an array, and then in_array to see if the number is there.

    if (!in_array($_data['mobile'], file('your_text_file.txt', FILE_IGNORE_NEW_LINES))) {
        $error .= "Mobile number not valid, please verify your number<br />";
    }