0

I am using Snoopy to extract a form from a website. The results of which look like this...

<form action="sendmessage.aspx">
<input type="hidden" name="" value="" />
<input type="hidden" value="103330268" name="usersendto" />
<input type="hidden" value="Bla343" name="sendto" />
<input type="hidden" value="94302158" name="p_id" />
<input type="hidden" value='' name='SID' />
<input type="hidden" value='' name='guid' />

What I want to do now is turn that, into this...

$p_data[''] = '';
$p_data['usersendto'] = '103330268';
$p_data['sendto'] = 'Bla343';
$p_data['p_id'] = '94302158';
$p_data['SID'] = '';
$p_data['guid'] = '';

Not a clue where to start...

1 Answers1

0

Snoopy will give you the HTML of the form as a string. You then need to manipulate it. To do HTML tags you should parse it as a DOM or, old school, you could carefully use regex.

$results = <<< EOF
<form action="sendmessage.aspx">
<input type="hidden" name="" value="" />
<input type="hidden" value="103330268" name="usersendto" />
<input type="hidden" value="Bla343" name="sendto" />
<input type="hidden" value="94302158" name="p_id" />
<input type="hidden" value='' name='SID' />
<input type="hidden" value='' name='guid' />
EOF;

$p_data=[];
preg_match_all("/<\s*input(.*?)>/sim",$results,$input_tags);
foreach ($input_tags[1] as $input_tag) {
    preg_match("/name\s*=\s*[\'\"](.*?)[\'\"]/sim",$input_tag,$name);
    preg_match("/value\s*=\s*[\'\"](.*?)[\'\"]/sim",$input_tag,$value);
    if (is_array($name) AND is_array($value)) {
        $p_data[$name[1]] = $value[1];
    }
}

foreach ($p_data as $key => $value) {
    print "'$key' = '$value'<br>";
}
Dean Jenkins
  • 194
  • 5