3v4l.org

run code in 300+ PHP versions simultaneously
<?php function splitEmail($str) { $pattern = "/([\w\s\'\"]+[\s]+)?(<)?(([\w-\.]+)@((?:[\w]+\.)+)([a-zA-Z]{2,4}))?(>)?/"; preg_match($pattern, $str, $match); return array( 'name' => isset($match[1]) ? trim($match[1]) : null, 'email' => isset($match[3]) ? trim($match[3]) : null, ); } $e = array( '<foo@bar.com>', 'Miguel <miguel@bar.com>', '"ddd" <123@d.com>', 'll\'f <ddd@ddd.ll>', 'foo@bar.com', ); foreach($e as $v) { var_dump(splitEmail($v)); }

preferences:
42.37 ms | 402 KiB | 5 Q