Solved

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

Posted on 2011-09-09
2
274 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…

749 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