Lost in Translation

Today I tryed to implement a functionality to create some CRM entities from email. I needed to retrieve an email, first name and last name (if possible) and body of the email. The last name is a mandatory property. I made a mistake when I used perlish style to initialize the last name:
preg_match('/\"(.*)\"\s+\< (.*)\>/', $from, $from_arr);
$names = preg_split('/\s+/', $from_arr[1]);
$email = $from_arr[2];
$first_name = $names[0];
$email_user = preg_match('/^(.*?)@/', $email);
$last_name = $names[1] || $first_name || $email_user;

But PHP is not Perl. I got “1” as the last name. So, I changed it on PHP manner:
$last_name = $names[1];
if(!$last_name) $last_name = $name[0];
if(!$last_name) $last_name = $email_user[1];

IMHO Perl variant is much better 🙂

Published by

Michael Stepanov

Site owner and admin :)

Leave a Reply

Your email address will not be published. Required fields are marked *