Zend - The PHP Company




Email

Add Code


Get Emails Addresses from Strings  

Type: code fragment
Added by: hermawan
Entered: 19/11/2003
Last modified: 02/11/2002
Rating: - (fewer than 3 votes)
Views: 5321
For you who needs to grab email addresses from string or from website which you've grabbed.


<?php
  
/*
  Snippet Name: Get Emails from Strings
  Author : Hermawan Haryanto
  Email : hermawan@codewalkers.com
  Homepage: http://hermawan.com
  Blog : http://hermawan.codewalkers.com
  */

  
function get_emails ($str)
  {
    
$emails = array();
    
preg_match_all("/bw+@w+[.w+]+b/"$str$output);
    foreach(
$output[0] as $emailarray_push ($emailsstrtolower($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);
?>


Usage Example




Rate This Script





Search



This Category All Categories