PHP Regex to remove nested form elements but not input elements
- by that0n3guy
I'm modifying a PHP script that I have and it is currently outputting a nested form. Something like:
<form name="input" action="html_form_action.asp" method="get">
<p>stuff here here, this may or may not be in a div, script, etc..</p>
<form name="input" action="html_form_action.asp" method="get">
<div>stuff here possibilly</div>
Username: <input type="text" name="user" />
<input type="submit" value="Submit" />
</form>
<p>otherstuff this may or may not be in a div, script, etc..</p>
</form>
Nested form's are a no-no (IE hates them and basically causes the form to stop working), so I need to remove the nested form lines, but not the form items. I need to remove the nested:
<form name="input" action="html_form_action.asp" method="get">
and
</form>
but not the outer <form and </form> or the input or submit stuff.
Is this possible to do with regex?
Note, the reason I just want to regex out the form rather than find the problem is because I know it will take some significant re-working to get rid of the double form... the regex solution is quick for now.