Jump to content

Look up value of an input of a form in html code?


nimedon

Recommended Posts

Hello

I was wondering if it's posible too look up for a value of an input in a html code, for example:

 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html >

blah blah

blah blah blah

<input type="hidden" name="hiddeninput1" value="hiddenvalue1">

blah blah

blah blah

<input type="hidden" name="hiddeninput2" value="hiddenvalue2">

</ html >

 

 

Let's say I got this html code in $html,

I need to get the values of hiddeninput1 and hiddeninput 2,

How can I do that?

 

Thanks

if your hidden tags code is consitant the below should work

 

<?php
$html = <<< EOS
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
blah blah
blah blah blah
<input type="hidden" name="hiddeninput1" value="hiddenvalue1">
blah blah
blah blah
<input type="hidden" name="hiddeninput2" value="hiddenvalue2">
</html>
EOS;

preg_match_all('#<input type="hidden" name="(.*?)" value="(.*?)">#', $html, $matches);

print_r($matches);

?>

hi, I can'get values, I only get this:

 

Array ( [0] => Array ( ) [1] => Array ( ) [2] => Array ( ) )

 

the problem is that some inputs are different, here's the html code I' trying to get values from:

 

<input type="hidden" name="__LBD_VCT" id="__LBD_VCT" value="31513402" />

<input type="hidden" name="__LBD_SGC_login_ctl00_cph_captcha" id="__LBD_SGC_login_ctl00_cph_captcha" value="0" />

<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTxFWnOLNY0=" />

<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWCK6HPm5vRj98" />

 

I now get this data:

 

Array ( [0] => Array ( [0] => type="hidden" name="__LBD_VCT" id="__LBD_VCT" value="31555373" [1] => type="hidden" name="__LBD_SGC_login_ctl00_cph_captcha" id="__LBD_SGC_login_ctl00_cph_captcha" value="0" [2] => type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDY0=" [3] => type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWCgLum++j98" ) [1] => Array ( [0] => __LBD_VCT" id="__LBD_VCT [1] => __LBD_SGC_login_ctl00_cph_captcha" id="__LBD_SGC_login_ctl00_cph_captcha [2] => __VIEWSTATE" id="__VIEWSTATE [3] => __EVENTVALIDATION" id="__EVENTVALIDATION ) [2] => Array ( [0] => 31555373 [1] => 0 [2] => /wEPDwnOLNY0= [3] => /wEWCgRj98 ) )

 

How do I do to make for example $__LBD_VCT = 31555373?

something like this should work

 

<?php
$html = <<< EOS
<input type="hidden" name="__LBD_VCT" id="__LBD_VCT" value="31513402" />
<input type="hidden" name="__LBD_SGC_login_ctl00_cph_captcha" id="__LBD_SGC_login_ctl00_cph_captcha" value="0" />
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTxFWnOLNY0=" />
<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWCK6HPm5vRj98" /> 
EOS;

preg_match_all('#<input type="hidden" name="(.*?)".*value="(.*?)" />#', $html, $matches);

print_r($matches);

?>

thanks! this is what I get now

 

 

Array (

 

[0] => Array ( [0] =>  [1] =>  [2] =>  [3] => )

[1] => Array ( [0] => __LBD_VCT [1] => __LBD_SGC_login_ctl00_cph_captcha [2] => __VIEWSTATE [3] => __EVENTVALIDATION )

[2] => Array ( [0] => 31626328 [1] => 0 [2] => /wEIY0= [3] => /wj98 )

 

)

 

do you know a way to get this donde:

$__LBD_VCT="31626328"

$ __LBD_SGC_login_ctl00_cph_captcha="0"

$__VIEWSTATE=" /wEIY0"

$__EVENTVALIDATION ="/wj98"

Yes try this new code out its much better than the previous one

 

<?php
$html = <<< EOS
<input type="hidden" name="__LBD_VCT" id="__LBD_VCT" value="31513402" />
<input type="hidden" name="__LBD_SGC_login_ctl00_cph_captcha" id="__LBD_SGC_login_ctl00_cph_captcha" value="0" />
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTxFWnOLNY0=" />
<input type="hidden"  id="__EVENTVALIDATION" value="/wEWCK6HPm5vRj98" name="__EVENTVALIDATION" /> 
EOS;

preg_match_all('#<input[^>]+>#', $html, $matches);

$matches = $matches[0];
$records = array();

foreach ($matches as $match) {
    $temp = array();
    preg_match_all('#([a-zA-Z]+?)="(.*?)"#', $match, $tag_matches);
    for ($i=0; $i < count($tag_matches[1]); $i++) {
        $temp[$tag_matches[1][$i]] = $tag_matches[2][$i];

    }
    if ($temp['type'] == 'hidden') {
        $records[] = $temp;
    }
}
print_r($records);

?>

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.