I have a function that uses comma as separator in breaking name/email pairs from a long string. I would like to modify this function to be able to detect if instead of a comma a line break is used. Here's the function that needs to be modified:
$str = '"Fname Lname" <abc@email.com>, abc@gmail.com';
$pairs = explode( ",", $str );
foreach( $pairs as $pair ) {
if( strpos($pair, '<') ) {
$output = explode( "<", $pair );
$output['0'] = trim( str_replace( "\"", "", $output['0'] ) );
$output['1'] = trim( rtrim( $output['1'], ">" ) );
} else {
$output = array();
$output['0'] = '';
$output['1'] = $pair;
}
print_r($output); // Save it to database here
}
I found a post suggesting using a file() fnction but I am not sure how to combine those two together.
$str = '"Fname Lname" <abc@email.com>, abc@gmail.com';
$pairs = file($str, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);