homepage Welcome to WebmasterWorld Guest from 54.166.255.168
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
PHP code to ignore text
drsmith

5+ Year Member



 
Msg#: 3527634 posted 1:18 pm on Dec 14, 2007 (gmt 0)

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 . " ";
}
fclose($handle);

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

Thanks
DS

 

d40sithui

5+ Year Member



 
Msg#: 3527634 posted 3:23 pm on Dec 14, 2007 (gmt 0)

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;
}

drsmith

5+ Year Member



 
Msg#: 3527634 posted 3:39 pm on Dec 14, 2007 (gmt 0)

That will work, thanks for the input.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved