Jump to content

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

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);
?>

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());
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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