Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

PHP code to ignore text



1:18 pm on Dec 14, 2007 (gmt 0)

5+ Year Member

I have some PHP code that reads in several .csv files. On occassion (since moving to Excel 2007) some extraneous characters/words tend to be introduced which is causing the mail program to fail. I am trying to put something in the code that will allow it to ignore everything except email addresses. Here is what I have right now:

# All
$allList = "";
$fileID = "/u2/text/confCall_Contacts/All.csv";
$handle = fopen($fileID, "r");
if ($handle) {
while (!feof ($handle)) {
$buffer = fgets ($handle, 4096);
$buffer = substr ($buffer, 0, -2);
list ($a, $b, $c, $d, $e, $f) = split (",", $buffer, 6);
$allList = $allList . $e . " ";

Any ideas how I can get it to just hit on the email addresses in the .csv file?



3:23 pm on Dec 14, 2007 (gmt 0)

5+ Year Member

you can use regular expressions to find only strings with valid email addresses. heres something i've come up with.

function validEmail($var){
$pattern = "/^[a-zA-Z0-9-_\.]+@{1}[a-zA-Z0-9-\.]+\.{1}[a-zA-Z]{2,4}$/"; //email pattern
if(preg_match($pattern, $var)){
return true;
return false;


3:39 pm on Dec 14, 2007 (gmt 0)

5+ Year Member

That will work, thanks for the input.

Featured Threads

Hot Threads This Week

Hot Threads This Month