0

I have a column of email addresses in a CSV file. I want to check if the email domain exist. I read the file using array as follow:

$domain = substr($arr[$line][$column], strpos($arr[$line][$column], '@') + 1);   
if  (checkdnsrr($domain) !== FALSE){
    echo $arr[$line][$column]. "    -->    Domain valid <br>";
}

The code works but how to ignore those lines which are empty in between? I get this line printed :

Warning: checkdnsrr(): Host cannot be empty in C:\xampp\htdocs\Trials\exist.php on line 18
1
  • How do you read the file? Commented Jun 2, 2014 at 3:50

2 Answers 2

1
 if (!empty($domain) and checkdnsrr($domain) !== FALSE) {

 }
Sign up to request clarification or add additional context in comments.

2 Comments

Now i am getting an error on the first line of my code: Notice: Undefined offset: 2 on line ...
Whats the line in question? It may be best to employ both this method and the method Hanky Panky suggested in the initial reading of the file.
1

you can use array_filter() to remove empty elements from the array:

array_filter($arr[$line]);

note: it should be an array inside of this array_filter function.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.