Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7884935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:55:58+00:00 2026-06-03T04:55:58+00:00

I do have a var like this: $mail_from = Firstname Lastname <email@domain.com>; I would

  • 0

I do have a var like this:

$mail_from = "Firstname Lastname <email@domain.com>";

I would like to receive either an

array(name=>"firstname lastname", email=>"email@domain.com")
or 
the values in two separate vars ($name = "...", $email = "...")

I have been playing around with preg_replace but somehow do not get it done …

Did extensive search but did not find a way to get this done.

This is the closest I got:

$str = 'My First Name <email@domain.com>';
preg_match('~(?:"([^"]*)")?\s*(.*)~',$str,$var);
print_r($var);
echo "<br>Name: ".$var[0];
echo "<br>Mail: ".$var[2];

How do I get “email@domain.com” into $var[‘x]?

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T04:55:59+00:00Added an answer on June 3, 2026 at 4:55 am

    This works for your example and should always work, when the email is within angle brackets.

    $str = 'My First Name <email@domain.com>';
    preg_match('~(?:([^<]*?)\s*)?<(.*)>~', $str, $var);
    print_r($var);
    echo "<br>Name: ".$var[1];
    echo "<br>Mail: ".$var[2];
    

    Explanation:

    (?:([^<]*?)\s*)? matches optionally everything that is not a < and everything except the trailing whitespace is stored in group 1.

    <(.*)> matches something between angle brackets and store it in group 2.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array like this: var arr1 = [a, b, c, d]; How
I have a code like this <script type=text/javascript> function email(){ var myTextField = document.getElementById('email_hidden').value;
I have an array and a var like this: $arrPs =array('p1','p2','pN'); $intVar = 80;
I have a string like this: var tempSting:String = abc@abc.com;xyz@xyz.com I want to add
I have code like this var MyObj = { f1 : function(o){ o.onmousedown =
I have a LINQ statement like this: var media = (from p in postService.GetMedia(postId)
I have an ordered list like this: var list = new List<String>(){aaa,aab,aac,baa,bab,bac}; I want
I have code that looks like this: var baseClass = function() { // CODE
I have some code like this: var content = document.getElementById('myDivId'); function MyFunction() { alert(content.style.height);
I have got code like this var challegneListener; $(document).ready(function(){ var challegneListener = setInterval(challengeListenerBot(),5000); });

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.