gamak Posted February 18, 2009 Share Posted February 18, 2009 Okay, So i'm a n00b at PHP, and I was hoping someone help me out. I have a form with one large text box which the user basically copies data into. The data copied into the text box looks like this: -------example of copied data--------------------------------------------- Peter Griffin <peterG@gmail.com>; Meg Griffin <meg@gmail.com>; Stewie Griffin <stewie@gmail.com> -------------------------------------------------------------------------- The form data is then sent to proccessbigtextboxpage.php ( I know how to do this) What I need to do is some how take the First Name and Last name and Email address and break it up and store it into a database. So I can get the data to look something like: $first_name = array("peter", "meg", "stewie"); $last_name = array ("griffin", "griffin", "griffin"); $email_address = array("peter@gmail.com", "stewie@gmail.com" , "meg@gmail.com"); I know how to store all of the data into a database, but I don't know how to break it all up to store it into a database. I think it has something to do with preg_match and PRCE or something, but I'm really lost. Quote Link to comment https://forums.phpfreaks.com/topic/145700-need-help-formating-form-data/ Share on other sites More sharing options...
farkewie Posted February 18, 2009 Share Posted February 18, 2009 Something like this may help. untested but should be close to what you want <?php foreach (split(";",$_POST['data']) as $person){ $details = split("<",$person); $name = $details[0]; $email = preg_replace('>','',$details[1]); $query = ""; //your job } ?> Quote Link to comment https://forums.phpfreaks.com/topic/145700-need-help-formating-form-data/#findComment-765208 Share on other sites More sharing options...
gamak Posted February 18, 2009 Author Share Posted February 18, 2009 I tried you code, but the output doesn't seem to be working for the emails. Here is what outputs when I use your code. <?php $email_list = $_POST['email']; foreach (split(";",$_POST['email']) as $person){ $details = split("<",$person); $name = $details[0]; $email = preg_replace('>','',$details[1]); echo " Name: $name \n "; echo " Email: $email \n"; //$query = ""; //your job } ?> -------------------Output------------ Name: Meg Griffin Email: Name: Peter Griffin Email: -------------------------------------- The email is blank. Quote Link to comment https://forums.phpfreaks.com/topic/145700-need-help-formating-form-data/#findComment-765273 Share on other sites More sharing options...
premiso Posted February 18, 2009 Share Posted February 18, 2009 $details = explode("<",$person); Explode may be better for that part, since it does not match patterns. To get the firstname/lastname separated, use explode and explode it by the space. Quote Link to comment https://forums.phpfreaks.com/topic/145700-need-help-formating-form-data/#findComment-765276 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.