E-Mail sample source codes

Get Email Addresses from Strings

<?php

  function get_emails ($str)
  {
    $emails = array();
    preg_match_all(“/\b\w+\@\w+[\.\w+]+\b/”, $str, $output);
    foreach($output[0] as $email) array_push ($emails, strtolower($email));
    if (count ($emails) >= 1) return $emails;
    else return false;
  }
  
  # Here is how to use it.
    
  # Sample string containing email addresses;
  $str = “test test@test.com ha ha heHe@test.com bla bla bla@test.com“;
  
  # Get the emails on arrays;
  $emails = get_emails ($str);
  
  # Print that arrays;
  print_r ($emails);
?>

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.