Solved

another PCRE question: need to match either display:none or visibility:hidden in the style attribute.

Posted on 2011-09-09
2
271 Views
Last Modified: 2012-06-21
hi there, the style attribute is retrieved using the php html dom class. i have used a regular expression to find either or, as in line 7 of the following function:
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;
}

Open in new window

what is wrong with this function or perl compatible regular expression that preg_match uses, that it does not return the expected results? 0o
the topmost parent is as follows within https://lmx.leads360.com/web/Login.aspx, as returned by file_get_contents.
<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>

Open in new window

if anybody can see why this would not be returning true or the matched text in the function ishidden, even be it as result of it's usage - please let me know.
0
Comment
Question by:intellisource
  • 2
2 Comments
 

Accepted Solution

by:
intellisource earned 0 total points
ID: 36510067
lol nvm - misread a reference earlier to retrieving the style attributes as $parent->$style instead of $parent->getAttribute('style') ;)
0
 

Author Closing Comment

by:intellisource
ID: 36510078
working now! i can get the form elements as an array, choose which ones need to be "displayed" for submission - and then compile the POST str ;)
perserverance is KEY! XD
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now