zeddeh Posted February 2, 2007 Share Posted February 2, 2007 Hello everyone, I had a pretty thorough look around this sites Tutorials, Code snippets and the like but I still can't see to find the answer to my question so I am hoping that someone may be able to assist me. In brief, I am trying to split an email address coming in from a database ($result[2]) into 2 parts: part_a will be all the text before the @ symbol and part_b will be everything after the @ symbol. I have found many references to validating an email but not spliting an email database query. I do not know, and can not seem to find, the proper syntax for this. The idea is to put part_a and part_b (see line 24) into an existing email scramble script (see below). The script works fine up to this point. At the moment it is displaying the email address ($result[2]) twice since I have part_a and part_b as the same. Any guidance would be appreciated. Many thanks! Newbie Zeddeh ----- start code --------- <?php #memberinfo.php /** This program accesses a mysql database where it retrieves and displays member information. */ require_once ("classes/HtmlTemplate2.class"); require_once ("../../config2.inc"); /**SET VARIABLES**/ if($_GET['pa'] == "1") { $main_page = new HtmlTemplate2 ("php_templates/memberinfo_private.html"); // Create an instance. }else{ $main_page = new HtmlTemplate2 ("php_templates/memberinfo.html"); // Create an instance. } //GATHER CONTENT $query = "SELECT * FROM surveyor where comm_no=".$_GET['member_id'].""; $query_result = mysql_query ($query, $db_connection) or die (mysql_error()); $num_rows = mysql_num_rows($query_result); $result = @mysql_fetch_array ($query_result, MYSQL_NUM); //this is where I want to split the incoming email address $part_a = $result[2]; $part_b = $result[2]; //FILL TEMPLATES $main_page->SetParameter("CSS", "class=\"memberInfoLeft\""); $main_page->SetParameter("CSS2", "class=\"memberInfoRight\""); $main_page->SetParameter("CSS3", "class=\"memberInfoCenter\""); $main_page->SetParameter("NAME", $result[5]); $main_page->SetParameter("EMAIL", "<script>function escramble(){ var a,b,c,d a='<a href=\"mai' b='$part_a' c='\">' a+='lto:' b+='@' d='</a>' b+='part_b' document.write(a+b+c+b+d) } escramble()</script>"); // original email query below //$main_page->SetParameter("EMAIL", $result[2]); $main_page->CreatePage(); exit; ?> ----- end code --------- Quote Link to comment https://forums.phpfreaks.com/topic/36747-solved-trying-to-split-an-email-database-query-into-2-sections/ Share on other sites More sharing options...
HuggieBear Posted February 2, 2007 Share Posted February 2, 2007 It should be as simple as using the explode() function in conjunction with the list() function... <?php $email = "huggiebear@domain.com"; list($before, $after) = explode('@', $email); ?> Regards Huggie Quote Link to comment https://forums.phpfreaks.com/topic/36747-solved-trying-to-split-an-email-database-query-into-2-sections/#findComment-175260 Share on other sites More sharing options...
zeddeh Posted February 2, 2007 Author Share Posted February 2, 2007 Hello Huggie, Yep, you're right! It is that simple. I had tried using the "explode" function before but it seems I was trying to make it to complicated. Much appreciated for your help and quick response! Gracias! Zeddeh Quote Link to comment https://forums.phpfreaks.com/topic/36747-solved-trying-to-split-an-email-database-query-into-2-sections/#findComment-175366 Share on other sites More sharing options...
HuggieBear Posted February 2, 2007 Share Posted February 2, 2007 You're welcome, there are a couple of other functions you could use, but this is the least memory intensive and the easiest in this situation I believe. Regards Huggie Quote Link to comment https://forums.phpfreaks.com/topic/36747-solved-trying-to-split-an-email-database-query-into-2-sections/#findComment-175371 Share on other sites More sharing options...
sayedsohail Posted February 3, 2007 Share Posted February 3, 2007 Thanks huggie, great stuff. Quote Link to comment https://forums.phpfreaks.com/topic/36747-solved-trying-to-split-an-email-database-query-into-2-sections/#findComment-176030 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.