How to I extract text between the "<>" tags?

Suppose I have this a variable with this value:

$eFrom = ""Joe Buck" <user@domain.com>";

What's the quickest way function that would allow me to extract the text between the <> tags?

In the above example, I'd like the end result to be:

$result = "user@domain.com"

I was thinking regular expressions, but struggle with writing them so I though someone here could assist.  Or maybe there is a better solution.
LVL 13
jrramAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

b0lsc0ttIT ManagerCommented:
jrram,

You could get it with ...

if (preg_match('/<([^>]*)>/', $eFrom, $regs)) {
      $result = $regs[1];
} else {
      $result = "";
}

Let me know if you have any questions or need more information.

b0lsc0tt
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jrramAuthor Commented:
Thanks, I'll try it out.

This is a longer solution I just created:

function getIT($e)
{
      $cp_from = strpos($e, "<", 0) + 1;
      $cp_to = strpos($e, ">", $cp_from);

        $cp_len = $cp_to - $cp_from;

      $e = substr($e, $cp_from, $cp_len);

      return $e;
}
0
jrramAuthor Commented:
Thanks b0lsc0tt,

Any sites you recommend that gives a good explanation of regular expressions.  I've Googled for it haven't come up with anything that explains it well.

0
b0lsc0ttIT ManagerCommented:
Your welcome!  I'm glad I could help.

One of the best helps for learning or making expressions is RegexBuddy (http://www.regexbuddy.com/).  That site also has a tutorial or manual that can be a great tool for learning regular expressions.  It comes with the program but I believe is available separately.  If you will be making expressions or are interested in them then the program is worth every penny.

The best source for learning or instructions is a book called Master Regular Expression by Jeff Freidl (http://www.oreilly.com/catalog/regex3/).  It is commonly thought of as the "bible" of regular expressions.

Some of my other favorite regex sites are:

http://blog.stevenlevithan.com/ - Not just regex but some great blogs on them
http://regexpal.com/ - A super Javascript based regex tester
http://www.evolt.org/article/Regular_Expression_Basics/20/22700/index.html

Finally, the Regex zone on this site has some great expression experts and a lot of questions that can really help those that need it.

Thanks for the grade, the points and the fun question.  I hope this info helps too.

bol
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.