LincolnC Posted January 19, 2012 Share Posted January 19, 2012 I'm *attempting* to write a script that will take a paste of data from a user and when it's submitted it will drop certain parts of the data into databases and be available for recall later. I have the MySQL sorta out I think but I can't test until I get this part done. Basically people will paste a copied paste (CTRL A, CTRL C and go to my form and just hit CTRL V). It will contain a bunch of data I want to drop in the database but in different areas, like the following example the items in bold are the items I want to grab. First Name: Lincoln Last Name: Coe Address: 1234 Easy St, Perfectville, PV 00000 Telephone: 0000000000 Quote Link to comment https://forums.phpfreaks.com/topic/255341-extracting-data/ Share on other sites More sharing options...
trq Posted January 19, 2012 Share Posted January 19, 2012 Cool. Do you have a question? Quote Link to comment https://forums.phpfreaks.com/topic/255341-extracting-data/#findComment-1309170 Share on other sites More sharing options...
LincolnC Posted January 19, 2012 Author Share Posted January 19, 2012 Yes, how on earth would you set it to grab that specific data? Quote Link to comment https://forums.phpfreaks.com/topic/255341-extracting-data/#findComment-1309231 Share on other sites More sharing options...
Muddy_Funster Posted January 19, 2012 Share Posted January 19, 2012 it's not the ideal way of doing it, but you could use: $array= array(); $string = trim($_POST['yourTextbox']); $array = explode(":", $string); $query = "INSERT INTO table (fist, last, address, telephone) VALUES ('{$array[1]}', '{$array[3]}', '{$array[5]}', '{$array[7]}')"; mysql_query($query) or die ("Something went badly wrong!<BR><BR>".mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/255341-extracting-data/#findComment-1309234 Share on other sites More sharing options...
litebearer Posted January 19, 2012 Share Posted January 19, 2012 It might be a good start to see how OP's form is setup before we move to the 'grabbing' , sanitizing, validating data stage. Quote Link to comment https://forums.phpfreaks.com/topic/255341-extracting-data/#findComment-1309235 Share on other sites More sharing options...
Muddy_Funster Posted January 19, 2012 Share Posted January 19, 2012 I was taking from the OP that there wasn't a form per-say, just a single field to paste the clipboard info into. Quote Link to comment https://forums.phpfreaks.com/topic/255341-extracting-data/#findComment-1309237 Share on other sites More sharing options...
litebearer Posted January 19, 2012 Share Posted January 19, 2012 I understand sometimes ill-written questions are tough to decipher OP's original and go to my form Quote Link to comment https://forums.phpfreaks.com/topic/255341-extracting-data/#findComment-1309238 Share on other sites More sharing options...
ManiacDan Posted January 19, 2012 Share Posted January 19, 2012 $input = 'First Name: Lincoln Last Name: Coe Address: 1234 Easy St, Perfectville, PV 00000 Telephone: 0000000000'; preg_match_all('/^([^:]+):\s*(.+)$/m', $input, $foo); foreach ( $foo[1] as $k => $label ) { echo "The value of {$label} is {$foo[2][$k]} <br />\n"; } Quote Link to comment https://forums.phpfreaks.com/topic/255341-extracting-data/#findComment-1309239 Share on other sites More sharing options...
LincolnC Posted January 19, 2012 Author Share Posted January 19, 2012 I wrote way too late at night by form I meant text box. Is there a way to only grab certain data even if it's all submitted? For example name, address and phone are submitted and I just want name and phone number Quote Link to comment https://forums.phpfreaks.com/topic/255341-extracting-data/#findComment-1309240 Share on other sites More sharing options...
ManiacDan Posted January 19, 2012 Share Posted January 19, 2012 Use the code I gave, and only use the value of $foo[2][$k] if the value of $label is in the list of what you want. Quote Link to comment https://forums.phpfreaks.com/topic/255341-extracting-data/#findComment-1309241 Share on other sites More sharing options...
litebearer Posted January 19, 2012 Share Posted January 19, 2012 Intrigued (being old and approaching senility), how is the data created on the client side, in this scenario, being sent to the server processing side? Quote Link to comment https://forums.phpfreaks.com/topic/255341-extracting-data/#findComment-1309243 Share on other sites More sharing options...
ManiacDan Posted January 19, 2012 Share Posted January 19, 2012 Intrigued (being old and approaching senility), how is the data created on the client side, in this scenario, being sent to the server processing side? I assume the output (being in label: value syntax) is being generated from another program which cannot be modified to do this post automatically. Quote Link to comment https://forums.phpfreaks.com/topic/255341-extracting-data/#findComment-1309245 Share on other sites More sharing options...
litebearer Posted January 19, 2012 Share Posted January 19, 2012 No offense, seriously confused here. 1. User on their computer 'cuts/copies' a piece of text (from whatever source and in whatever format). 2. User pastes the text into a textbox . 3. What action/mechanism is being used by the client side to send the value from the text box (clientside) to the php processing script (server side)? ajax/form/??? Quote Link to comment https://forums.phpfreaks.com/topic/255341-extracting-data/#findComment-1309248 Share on other sites More sharing options...
ManiacDan Posted January 19, 2012 Share Posted January 19, 2012 He said they go to his form and paste a large text block. The assumption is, then, that he has a textarea inside a form. The post method doesn't matter to the question. Quote Link to comment https://forums.phpfreaks.com/topic/255341-extracting-data/#findComment-1309251 Share on other sites More sharing options...
litebearer Posted January 19, 2012 Share Posted January 19, 2012 Again, truly no offense. As OP is irregular, and has not shown ANY of his code, we don't know: 1. is he using get or post. 2. is user complying with 'cut/paste' OR is user typing in data 3. if user is typing data, is user following the format described (ie the colon) Additionally, I would think (IMHO) that the OP would be better served if we saw the code OP has tried thus far (both the form and the processing). Quote Link to comment https://forums.phpfreaks.com/topic/255341-extracting-data/#findComment-1309255 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.