CodeIgniter Forums
how to separat the emails that i have ?? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: how to separat the emails that i have ?? (/showthread.php?tid=17330)

Pages: 1 2


how to separat the emails that i have ?? - El Forum - 04-02-2009

[eluser]frrose[/eluser]
hi all !

i want to ask

if I have many Email like this exo@yahoo.com;[email protected];[email protected];[email protected]


and i want to insert it in database but each email is alone in one record how ??


and i want it to be in form to use it any time i want Smile

thanks ..


how to separat the emails that i have ?? - El Forum - 04-02-2009

[eluser]gyo[/eluser]
Code:
$emails_string = "[email protected];[email protected];[email protected];[email protected]";
$emails_array = explode(";",$emails_string);

Then you just have to loop through $emails_array and insert each item into the database.

Btw... are you sure that you're not going to send spam? Tongue


how to separat the emails that i have ?? - El Forum - 04-02-2009

[eluser]frrose[/eluser]
No i won't

but Grad Student
lets say that we have an wrong email on it ?
or some of this emails dont have ;
or if tehy change the ; in new line

then how Smile ??


how to separat the emails that i have ?? - El Forum - 04-02-2009

[eluser]Thorpe Obazee[/eluser]
o.o

huh? maybe you can explain the situation?


how to separat the emails that i have ?? - El Forum - 04-02-2009

[eluser]gyo[/eluser]
To check the email addresses you can use the valid_email function.

For the second problem you should define a separator and stuck with it; if this is not possible then you can do some regular expression to search for *@*.* where the asterisks are the user, the domain and the extension.
Basically you want to search for [email protected]

Hope that helps.

gyo


how to separat the emails that i have ?? - El Forum - 04-02-2009

[eluser]frrose[/eluser]
sorry suashi ..
but i didnt understand how to solve the second problem :blank:
could you give me an example if you dont mind


how to separat the emails that i have ?? - El Forum - 04-02-2009

[eluser]gyo[/eluser]
I just found something that you could use:

Code:
<?php
/*
Snippet Name: Get Emails from Strings
Author : Hermawan Haryanto
Email : [email protected]
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 [email protected] ha ha [email protected] bla bla [email protected]";

# Get the emails on arrays;
$emails = get_emails ($str);

# Print that arrays;
print_r ($emails);
?>

$emails will be the array containing all the addresses, so you can go through it with a loop.


how to separat the emails that i have ?? - El Forum - 04-02-2009

[eluser]frrose[/eluser]
oh that is great Smile

thank you man Smile


how to separat the emails that i have ?? - El Forum - 04-02-2009

[eluser]gyo[/eluser]
No problem, I only hope you'll not make an email spider! Tongue


how to separat the emails that i have ?? - El Forum - 04-02-2009

[eluser]frrose[/eluser]
no dont worry
i will not