Answers for "php extract email address from string"

PHP
0

php extract email address from string

<?php 
    $string = 'Ruchika < [email protected] >';
    $pattern = '/[a-z0-9_\-\+\.]+@[a-z0-9\-]+\.([a-z]{2,4})(?:\.[a-z]{2})?/i';
    preg_match_all($pattern, $string, $matches);
    var_dump($matches[0]);
?>
Posted by: Guest on July-22-2021
0

php extract email from string

<?php
function fetch_mails($text){
    
  //String that recognizes an e-mail
    $str = '/([a-z0-9_\.\-])+\@(([a-z0-9\-])+\.)+([a-z0-9]{2,4})+/i';
    preg_match_all($str, $text, $out);
  //return a blank array if not true otherwise insert the email in $out and return
    return isset($out[0]) ? $out[0] : array();
}
//string to be checked
$tstr = '
My first e-mail address is [email protected]
My second e-mail address is [email protected]
Obviously this is not a emaail address: code__speedy@^gmail.co.in
';
//display email addresses
echo"<pre>";
print_r(fetch_mails($tstr));
?>
Posted by: Guest on July-28-2021

Code answers related to "php extract email address from string"

Browse Popular Code Answers by Language