PHP: Find Email in String


/ Published in: PHP
Save to your folder(s)

Thank you Jonathan Sampson for posting this on http://stackoverflow.com/questions/2050789/php-search-a-string-for-a-email-address


Copy this code and paste it in your HTML
  1. <?php
  2. $content = "Hi my name is Joe, I can be contacted at [email protected].";
  3. preg_match("/[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})/i", $content, $matches);
  4. print $matches[0];
  5. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.