How to efficiently extract names and emails from a contact list?
<p>I'd like to allow users to paste in a list of <em>new line</em> separated contacts and have an array of names and emails generated efficiently.</p>

<p>Let's say the possibilities of the entries are:</p>

<pre><code>John, foo@corp.com
foo@corp.com, John
John foo@corp.com
foo@corp.com John
foo@corp.com // will have the [name] key empty
John // will not be considered if there is no email
</code></pre>

<p>Currently my solution is to <code>explode</code> by <code>\n</code> then explode by commas then guess where the email and names are. I admit that this is totally unreliable and that's why i'd like to see how others can approach this.</p>

<p>The array i'm trying to come up with is like:</p>

<pre><code>array(
 [0] =&gt; array(
         [name] =&gt; John,
         [email] =&gt; foo@corp.com
        )
 [1] =&gt; ...
)
</code></pre>

<p>Any ideas?</p>
