Skip to content
Advertisement

Create an array include email

I am trying to create a function to extract email to send but I do not find the solution

Thank you

email type : contact<contact@contact.com>, contact1<contact1@contact.com>

the function

JavaScript

and after I make a loop via foreach.

Advertisement

Answer

You could make use of array_map and array_filter to sanitize email addresses and remove invalid ones:

JavaScript

Usage:

JavaScript

Basically:

  • preg_match_all gathers all (supposed) email addresses within $matches['email']
  • array_map sanitizes and validates said email addresses (null is returned if one is invalid)
  • array_filter finally removes all null values.

Demo

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement