title: php - preg_replace / backreference - Syntax to extract parts from mail address
body: <p>I do have a var like this:</p>
  
  <pre><code>$mail_from = "Firstname Lastname &lt;email@domain.com&gt;";
  </code></pre>
  
  <p>I would like to receive either an </p>
  
  <pre><code>array(name=&gt;"firstname lastname", email=&gt;"email@domain.com")
  or 
  the values in two separate vars ($name = "...", $email = "...")
  </code></pre>
  
  <p>I have been playing around with preg_replace but somehow do not get it done ... </p>
  
  <p>Did extensive search but did not find a way to get this done.</p>
  
  <p>This is the closest I got:</p>
  
  <pre><code>$str = 'My First Name &lt;email@domain.com&gt;';
  preg_match('~(?:"([^"]*)")?\s*(.*)~',$str,$var);
  print_r($var);
  echo "&lt;br&gt;Name: ".$var[0];
  echo "&lt;br&gt;Mail: ".$var[2];
  </code></pre>
  
  <p>How do I get "email@domain.com" into $var['x]?</p>
  
  <p>Thank you.</p>