nimedon Posted December 1, 2009 Share Posted December 1, 2009 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 Link to comment https://forums.phpfreaks.com/topic/183653-look-up-value-of-an-input-of-a-form-in-html-code/ Share on other sites More sharing options...
rajivgonsalves Posted December 1, 2009 Share Posted December 1, 2009 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); ?> Link to comment https://forums.phpfreaks.com/topic/183653-look-up-value-of-an-input-of-a-form-in-html-code/#findComment-969333 Share on other sites More sharing options...
nimedon Posted December 1, 2009 Author Share Posted December 1, 2009 hi, thanks for your answer, I tried your code this is what I'm getting: Array ( [0] => Array ( ) [1] => Array ( ) [2] => Array ( ) ) do you know how can I know the value and name of each array? Link to comment https://forums.phpfreaks.com/topic/183653-look-up-value-of-an-input-of-a-form-in-html-code/#findComment-969340 Share on other sites More sharing options...
rajivgonsalves Posted December 1, 2009 Share Posted December 1, 2009 that code will work as it is if the html changes of the hidden files you will have to change the regular expression depending on html for the hidden input tags Link to comment https://forums.phpfreaks.com/topic/183653-look-up-value-of-an-input-of-a-form-in-html-code/#findComment-969344 Share on other sites More sharing options...
nimedon Posted December 1, 2009 Author Share Posted December 1, 2009 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" /> Link to comment https://forums.phpfreaks.com/topic/183653-look-up-value-of-an-input-of-a-form-in-html-code/#findComment-969350 Share on other sites More sharing options...
nimedon Posted December 1, 2009 Author Share Posted December 1, 2009 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? Link to comment https://forums.phpfreaks.com/topic/183653-look-up-value-of-an-input-of-a-form-in-html-code/#findComment-969351 Share on other sites More sharing options...
rajivgonsalves Posted December 1, 2009 Share Posted December 1, 2009 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); ?> Link to comment https://forums.phpfreaks.com/topic/183653-look-up-value-of-an-input-of-a-form-in-html-code/#findComment-969352 Share on other sites More sharing options...
nimedon Posted December 1, 2009 Author Share Posted December 1, 2009 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" Link to comment https://forums.phpfreaks.com/topic/183653-look-up-value-of-an-input-of-a-form-in-html-code/#findComment-969359 Share on other sites More sharing options...
rajivgonsalves Posted December 1, 2009 Share Posted December 1, 2009 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); ?> Link to comment https://forums.phpfreaks.com/topic/183653-look-up-value-of-an-input-of-a-form-in-html-code/#findComment-969364 Share on other sites More sharing options...
nimedon Posted December 1, 2009 Author Share Posted December 1, 2009 thank you rajivgonsalves! really helpfull, keep good work! Link to comment https://forums.phpfreaks.com/topic/183653-look-up-value-of-an-input-of-a-form-in-html-code/#findComment-969369 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.