Parse Emails From a String

Handy one for all sorts of reasons, just don’t use it for evil : \. I also did an online working version of this function. It takes a string and returns an array of unique emails parsed out.

function parseEmailsFromString($text, $unique = true) {
	preg_match_all('/[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*(\\.[_A-Za-z0-9-]+)/', $text, $result);
	for ($i = 0; $i < count($result[0]); $i++) {
			if(!in_array($result[0][$i], $mails)) $mails[] = $result[0][$i];
			$mails[] = $result[0][$i];
	return $mails;