Jump to content

Another Pcre Question: Need To Match Either Display:none Or Visibility:hidden In A Parental Style Attribute


Greywacke
 Share

Recommended Posts

hi, yet another regex issue, meh -_-to match the following PCRE (or similar) within the style attribute of a parent element to an element passed by name, using the preg_match function in line 7./display\s*:\s*none|visibility[\s]*:[\s]*hidden/inow to my knowledge, that will match either display:none, display :none, display : none or display: none as well as either visibility:hidden, visibility :hidden, visibility : hidden or visibility: hidden.the function below uses the extracted form html section and the dom is parsed using the PHP Simple HTML DOM Parser API Class.

function ishidden($name,$html) {$str = str_get_html($html);//print_r($str);$parent = $str->find("[name=".$name."]",0);//print_r($parent);while ($parent = $parent->parent()) {  if (preg_match("/display\s*:\s*none|visibility[\s]*:[\s]*hidden/i",$parent->$style,$match)) {   return $match[0];  }}return false;}

somebody please help asap on this issue, i have a deadline to meet. :(

Edited by Pierre 'Greywacke' du Toit
Link to comment
Share on other sites

ok the value returned seems to be false :(there HAS to be something wrong with the regular expression! :/ the form i am testing with is https://lmx.leads360.../web/Login.aspx - and look at the source for yourself - the element emailTextBox's topmost parent is as follows:

<div id="passwordDialog" style="position:absolute;visibility:hidden;height:;width:;" class="dialog"><div id="passwordDialog_HeaderSpan" class="header">   		    Forgot Password	   </div><div id="passwordDialog_InnerSpan" class="content password">   		    <p>Please enter the email address you signed up with and we will send you a new login link.</p>		    <dl>			    <dt>Email:</dt>			    <dd><input name="emailTextBox" type="text" id="emailTextBox" class="bigtextbox" /></dd>		    </dl>		    <div class="buttons submitcancel">			    <a class="submit left" id="submitPasswordRest" onclick="RequestPasswordReset();">Submit</a>			    <a class="cancel right" onclick="passwordDialog.Close();">Close</a>		    </div>	   </div><div id="passwordDialog_FooterSpan" class="footer">   	   </div></div>[/codeBOX]

yet for some strange reason it is not echoing the parent styles or returning true with the following two functions (the second retrieves an array of form elements but prints the hidden field as displayed - the problem could also be in the [b]"input"[/b] case below, in the [b]switch($element[1])[/b]):

[codeBOX]function ishidden($name,$html) { $str = str_get_html($html); $parent = $str->find("[name=".$name."]",0); while ($parent = $parent->parent()) { if (preg_match("/(display|visibility)\s*:\s*(none|hidden)/i",$parent->$style,$match)) { //print_r($parent); echo "style = ".$parent->$style."\n"; return $match[0]; } } return false;}function getforms($html) { /* - load form as: array( [type], [name], [value], [checked], [disabled] ); */ $ret = array(); $forms = array(); preg_match_all("/\<form [^\>]+\>.*\<\/form\>/ims", $html, $out); //print_r($out); foreach ($out[0] as $form) { array_push($forms,$form); } foreach ($forms as $form) { //echo $form."\n"; $pattern = '/<(form)(?=(?:[^>]*name="([^"]*))?)(?=(?:[^>]*action="([^"]*))?)' . '|<(input)(?=(?:[^>]*type="([^"]*))?)(?=(?:[^>]*name="([^"]*))?)(?=(?:[^>]*value="([^"]*))?)(?=(?:[^>]*checked="([^"]*))?)(?=(?:[^>]*disabled="([^"]*))?)' . '|<(textarea)(?=(?:[^>]*name="([^"]*))?)[^>]*>([^<]|<(?!\/textarea))(?=(?:[^>]*disabled="([^"]*))?)' . '|<(select)(?=(?:[^>]*name="([^"]*))?)(?=(?:[^>]*disabled="([^"]*))?)' . '|<(button)(?=(?:[^>]*name="([^"]*))?)(?=(?:[^>]*disabled="([^"]*))?)/i'; //$pattern = '/\<(form).*name="([^"]+)".*action="([^")".*\>'. // '|\<(input).*type="([^"]+)".*name="([^"]+)".*value="([^"]+)".*checked="([^"]+)".*\/\>'. // '|\<(textarea).*name="([^"]+)".*\>(.*)*\<\/textarea\>'. // '|<(select).*name="([^"]+)".*>'. // '|<(button).*name="([^"]+)".*value="([^"]+)".*>/ims'; preg_match_all($pattern, $form, $out, PREG_SET_ORDER); $out = array_non_empty_items($out); $i = 0; foreach ($out as $element) { $ret[$i] = array(); switch ($element[1]) { case "form": array_push($ret[$i], array( "type" => $element[1], "name" => $element[2], "action" => $element[3] ) ); break; case "input": array_push($ret[$i], array( "input" => $element[1], "type" => $element[2], "name" => $element[3], "value" => $element[4], "checked" => ((($element[2]=="radio"||$element[2]=="checkbox")?true:false)?"true":"false"), "disabled"=> (($element[2]=="radio"||$element[2]=="checkbox")?(($element[6]=="true"||$element[6]=="disabled")?true:false):(($element[5]=="true"||$element[5]=="disabled")?true:false))||(ishidden($element[3],$form))?"true":"false" ) ); print_r(ishidden($element[3],$form)); break; case "textarea": array_push($ret[$i], array( "input" => $element[1], "name" => $element[2], "value" => $element[3], "disabled"=> ($element[4]=="true"||$element[4]=="disabled"||ishidden($element[2],$form))?"true":"false" ) ); break; case "select": array_push($ret[$i], array( "input" => $element[1], "name" => $element[2], "value" => getoption($element[2],$form), "disabled"=> ($element[4]=="true"||$element[4]=="disabled"||ishidden($element[2],$form))?"true":"false" ) ); break; case "button": array_push($ret[$i], array( "input" => $element[1], "name" => $element[2], "value" => $element[3], "disabled"=> ($element[4]=="true"||$element[4]=="disabled"||ishidden($element[2],$form))?"true":"false" ) ); break; } $i++; } } return $ret;}[/codeBOX]

Edited by Pierre 'Greywacke' du Toit
Link to comment
Share on other sites

lol nvm - misread a reference earlier to retrieving the style attributes as $parent->$style instead of $parent->getAttribute('style') ;)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...