phoenixx Posted May 13, 2008 Share Posted May 13, 2008 What I'm doing is pretty simple, but can't seem to get it to work? An external site holds the following data (with the long strings being random or at least pseudorandom). <!-- Sample Data --> <input type="hidden" name="U2FsdGVkX18goKhw3PNp1hoNW1XtlDrynp2vpujLUk91T-mrCFgp_zPaHUQ0ntTK1qkDcubva4Y" value="test"> <input type="hidden" name="U2FsdGVkX185P0eiDtlWUsO1e5nu-uKU9zRVqCup_wQaMp55L082EJ9d1z8AGEd9bOEQRrJII0U" value="Test"> <input type="hidden" name="test" value="v335d"> <input type="hidden" name="postingKey" value="uLLKc4c9H4h5QZoe"> <input type="hidden" name="U2FsdGVkX1_tQgrdT02gqfhvLU9azdevjvwPNGRYZ1bLpPLQrw6n3Aq4q2uqoUC6" value="C"> <input type="hidden" name="U2FsdGVkX18L31E19JPgAISK-7vJbKFiOvwvOIL0ffYr-vWaUykl9OM7NOqr8cYz" value="Test"> <input type="hidden" name="FromEMail" value="samples@mydomain.net"> <input type="hidden" name="Type" value="B"> <input type="hidden" name="mix" value=""> <input type="hidden" name="contactEmail" value=""> <!-- End Sample Data --> I just need to extract the field name and value and submit it to the database... with the understanding that the "U2FsdGVkX18....." names are dynamic. How do I go about parsing and extracting the name and value? Thanks in advace. Quote Link to comment https://forums.phpfreaks.com/topic/105463-solved-extract-amp-parse-form-field-values-from-external-site/ Share on other sites More sharing options...
sasa Posted May 13, 2008 Share Posted May 13, 2008 try <?php $data ='<!-- Sample Data --> <input type="hidden" name="U2FsdGVkX18goKhw3PNp1hoNW1XtlDrynp2vpujLUk91T-mrCFgp_zPaHUQ0ntTK1qkDcubva4Y" value="test"> <input type="hidden" name="U2FsdGVkX185P0eiDtlWUsO1e5nu-uKU9zRVqCup_wQaMp55L082EJ9d1z8AGEd9bOEQRrJII0U" value="Test"> <input type="hidden" name="test" value="v335d"> <input type="hidden" name="postingKey" value="uLLKc4c9H4h5QZoe"> <input type="hidden" name="U2FsdGVkX1_tQgrdT02gqfhvLU9azdevjvwPNGRYZ1bLpPLQrw6n3Aq4q2uqoUC6" value="C"> <input type="hidden" name="U2FsdGVkX18L31E19JPgAISK-7vJbKFiOvwvOIL0ffYr-vWaUykl9OM7NOqr8cYz" value="Test"> <input type="hidden" name="FromEMail" value="samples@mydomain.net"> <input type="hidden" name="Type" value="B"> <input type="hidden" name="mix" value=""> <input type="hidden" name="contactEmail" value=""> <!-- End Sample Data --> '; preg_match_all('/<input.*?name="([^"]*)".*?value="([^"]*)"/is',$data,$out); $d = array_combine($out[1], $out[2]); print_r($d); ?> Quote Link to comment https://forums.phpfreaks.com/topic/105463-solved-extract-amp-parse-form-field-values-from-external-site/#findComment-540202 Share on other sites More sharing options...
phoenixx Posted May 13, 2008 Author Share Posted May 13, 2008 Worked great. Is there a way to assign variables to the name and values to export it to a MySQL Database? Quote Link to comment https://forums.phpfreaks.com/topic/105463-solved-extract-amp-parse-form-field-values-from-external-site/#findComment-540230 Share on other sites More sharing options...
GingerRobot Posted May 13, 2008 Share Posted May 13, 2008 You can just insert new rows based on the contents of the array: <?php $data ='<!-- Sample Data --> <input type="hidden" name="U2FsdGVkX18goKhw3PNp1hoNW1XtlDrynp2vpujLUk91T-mrCFgp_zPaHUQ0ntTK1qkDcubva4Y" value="test"> <input type="hidden" name="U2FsdGVkX185P0eiDtlWUsO1e5nu-uKU9zRVqCup_wQaMp55L082EJ9d1z8AGEd9bOEQRrJII0U" value="Test"> <input type="hidden" name="test" value="v335d"> <input type="hidden" name="postingKey" value="uLLKc4c9H4h5QZoe"> <input type="hidden" name="U2FsdGVkX1_tQgrdT02gqfhvLU9azdevjvwPNGRYZ1bLpPLQrw6n3Aq4q2uqoUC6" value="C"> <input type="hidden" name="U2FsdGVkX18L31E19JPgAISK-7vJbKFiOvwvOIL0ffYr-vWaUykl9OM7NOqr8cYz" value="Test"> <input type="hidden" name="FromEMail" value="samples@mydomain.net"> <input type="hidden" name="Type" value="B"> <input type="hidden" name="mix" value=""> <input type="hidden" name="contactEmail" value=""> <!-- End Sample Data --> '; preg_match_all('/<input.*?name="([^"]*)".*?value="([^"]*)"/is',$data,$out); $d = array_combine($out[1], $out[2]); $insert_into = array(); foreach($d as $k=>$v){ $insert_into[] = '('.$k.','.$v.')'; } $insert_into = implode(',',$insert_into); mysql_query("INSERT INTO yourtable(fieldname,fieldvalue) VALUES $insert_into") or die(mysql_error()); ?> Quote Link to comment https://forums.phpfreaks.com/topic/105463-solved-extract-amp-parse-form-field-values-from-external-site/#findComment-540240 Share on other sites More sharing options...
phoenixx Posted May 13, 2008 Author Share Posted May 13, 2008 Many thanks. It worked great! Quote Link to comment https://forums.phpfreaks.com/topic/105463-solved-extract-amp-parse-form-field-values-from-external-site/#findComment-540257 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.