Regular Expression with Names and Emails
- by Nina
I am having a problem with regular expressions at the moment.
What I'm trying to do is that for each line through the iteration, it checks for this type of pattern: Lastname, Firstname
If it finds the name, then it will take the first letter of the first name, and the first six letters of the lastname and form it as an email.
I have the following:
$checklast = "[A-z],";
$checkfirst = "[A-z]";
if (ereg($checklast, $parts[1])||ereg($checkfirst, $parts[2])){
$first = preg_replace($checkfirst, $checkfirst{1,1}, $parts[2]);
print "<a href='mailto:[email protected];'> $parts[$i] </a>";
}
This one obviously broke the code. But I was initially attempting to find only the first letter of the firstname and then after that the first six letters of the lastname followed by the @email.com This didn't work out too well. I'm not sure what to do at this point.
Any help is much appreciated.