$cadenas = ["pepe@pepe.com", "ola k ase??", "@@@....", "hola.ssss@mmv", "pepe.com", "pepe@pepe"]; //Recorrer con for for ($i = 0; $i < count($cadenas); $i++) { echo ($i + 1) . ".- " . $cadenas[$i] . (esMail2($cadenas[$i]) ? '' : ' no ') . " es mail.<br/>"; } //Recorrer con foreach foreach($cadenas as $cadena){ echo $cadena . (esMail3($cadena) ? '' : ' no ') . " es mail.<br/>"; } function esMail($cadena) { $pos1 = strpos($cadena, "@"); $pos2 = strpos($cadena, "."); if ($pos1 !== false && $pos2 !== false && $pos2 > $pos1) { return true; } else { return false; } } function esMail3($cadena) { $pos1 = strpos($cadena, "@"); $pos2 = strpos($cadena, ".",$pos1); return ($pos1 != false && $pos2 !== false); } function esMail2($cadena) { if ($pos = strpos($cadena, "@")) { return strpos($cadena, ".", $pos); } return false; } function esMailReg($cadena){ return preg_match( '/^[^0-9][a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)*[@][a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)*[.][a-zA-Z]{2,4}$/', $cadena); } function buscaMail($cadena){ $pattern="/(?:[A-Za-z0-9!#$%&'*+=?^_`{|}~-]+(?:\.[A-Za-z0-9!#$%&'*+=?^_`{|}~-]+)*|\"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*\")@(?:(?:[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?\.)+[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[A-Za-z0-9-]*[A-Za-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])/"; preg_match_all($pattern,$cadena,$mails); return $mails; }