Regular Expression with Names and Emails

Posted by Nina on Stack Overflow See other posts from Stack Overflow or by Nina
Published on 2012-10-30T04:43:59Z Indexed on 2012/10/30 5:00 UTC
Read the original article Hit count: 224

Filed under:
|
|

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.

© Stack Overflow or respective owner

Related posts about php

Related posts about regex