For you guys who needs to grab email addresses either from string or from a web page you've grab. Here is the code.
By : hermawan
<?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("/\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); ?>
DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.