Jump to content

Script to catch email addresses in paragraph.


salman_ahad@yahoo.com

Recommended Posts

 

I have a pragraph full of email addresses. I need to catch emails only and ignore the rest.

 

if ($_POST['Submit'])
{
$para = $_POST['para'];
        $emails = split('[<>;:,\/"{}*!?]',$para);	
        foreach ($emails as $email)
           {
        	if (empty($email)) {
                continue;} //I need help here for deleting those empty rows.
       else {
               // echo $email.'<br \>';
               // or insert in database.....
............
                     }
            }
}

 

Also I need help applying this email validation ereg, guide me here too please

 

$regexp = "^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,4})$";

//or

'/^[a-zA-Z0-9._-]+@[a-zA-Z0-9-]+\.[a-zA-Z.]{2,5}$/'

//or Anything better before inserting in database??

Link to comment
Share on other sites

 

Yes I think it should be in regex, but I dont know how ??

 

My updated code

 

if ($_POST['Submit'])
{
$para = $_POST['para'];
        $emails = split('[<>;:,\/"{}*!?]',$para);	
foreach ($emails as $email)
	{
	if (empty($email)) {
        	continue;}
	if(stristr($email, '@') === FALSE) {  //Checking for those strings containing '@'
	continue;}
	else {
			echo $email.'<br \>';
		}
	}
}

 

My output is almost there...but I am also getting strings like

 


name@yahoo.co.in ---------- Forwarded message ---------- From

//in these type of strings I think need to use regex... any help

Link to comment
Share on other sites

 

Now this is my updated code to take junk of data and catch only email addresses.

 

<?php
if ($_POST['Submit'])
{
$para = $_POST['para'];
$emails = preg_split( '@[ <>;:,\\\\/"{}*!?]@', $para ); //split the para when there are signs encountered, excluding '@', '.', '_'
foreach ($emails as $email)
	{
	if (empty($email)) {
    	continue;}
	if(stristr($email, '@') === FALSE) {
	continue;}
       	else {
		echo $email.'<br \>';
		continue;
		}
	}
}
//$regexp = '/^[a-zA-Z0-9._-]+@[a-zA-Z0-9-]+\.[a-zA-Z.]{2,5}$/';
?>

 

Now this is my input data

 


abwbasit2002@yahoo.com

---- Forwarded Message ----
From: Sattar <sattardiq@gmail.com>
To: wajihah7@yahoo.com
Sent: Tue, November 17, 2009 9:23:57 AM

 

My output is like

 


abwbasit2002@yahoo.com -----             // notice '-----' at the end, I need to omit that.
sattardiq@gmail.com
wajihah7@yahoo.com Sent                    //notice 'Sent' at the end, I need to omit that.

//Dont know how to modify my code more to remove those

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.