Jump to content

[SOLVED] Extract & Parse Form Field Values from External Site


phoenixx

Recommended Posts

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="[email protected]">

<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.

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="[email protected]">
<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);
?>

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="[email protected]">
<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());
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.