3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $string = "ukahfranklin@yahoo.com, abhishek.b@contecglobal.com, Ukah Franklin B , <<option1>>, <<<option2>>>, Okechukwu Second name\n Abuja Airport, abvairport@contecglobal.com,<<<this option2>>>\n accounts.abuja@contecglobal.com, Accounts Abuja \n dejiashiru@contecglobal.com, Adeji Ashiru "; $result=array(); $no=0; $var = explode("\n",$string); foreach($var as $v){ $w = preg_split('/[,;]/',$v); foreach($w as $l){ if(preg_match('/((?<option2>(<{3}.+>{3}))|(?<option1>(<{2}.+>{2}))|(?<email>([a-zA-Z0-9.!#$%&?+\/=?^_`{|}~-]+@{1}[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]{2,}){1,11}))|(?<name>([^<>]{2,10}[\w\W])+))/', $l, $matches)){ if(!empty($matches['option2'])){$result[$no]['option2']=$matches['option2'];} if(!empty($matches['option1'])){$result[$no]['option1']=$matches['option1'];} if(!empty($matches['email'])){$result[$no]['email']=$matches['email'];} if(!empty($matches['name'])){$result[$no]['name']=$matches['name'];} } } $no++; } print("<pre>".print_r($result,true)."</pre>"); exit();
based on LWZtF
Output for 5.6.38 - 7.2.11
<pre>Array ( [0] => Array ( [email] => ukahfranklin@yahoo.com [name] => Okechukwu Second name [option1] => <<option1>> [option2] => <<<option2>>> ) [2] => Array ( [name] => abvairport@contecglobal.com [option2] => <<<this option2>>> ) [4] => Array ( [email] => accounts.abuja@contecglobal.com [name] => Accounts Abuja ) [6] => Array ( [email] => dejiashiru@contecglobal.com [name] => Adeji Ashiru ) ) </pre>