Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2011-09-09
2
Medium Priority
?
279 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
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…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses
Course of the Month21 days, 7 hours left to enroll

804 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