Page 1 of 1

Grab text between two strings

Posted: Wed Aug 16, 2006 2:25 pm
by d3ad1ysp0rk
I have a block of text, and I need to end up with an array of values.

Text will look something like this:

Code: Select all

blah blah lbah
blah blah lbah
blah blah lbah
To: Justin@email.com
blah blah lbah

blah blah lbah
blah blah lbah
To: Michelle@email.com
blah blah lbah
blah blah lbah
From that, I need to get an array of the emails, so, match whatever is between "To: " and "\n"?

Could anyone give me some hints as how to do this effeciently?

Posted: Wed Aug 16, 2006 2:28 pm
by feyd

Code: Select all

preg_match_all('#^\s*to:\s*.*?$#im', $yourTest, $matches);
print_r($matches);