PHP Regex to remove nested form elements but not input elements
Posted
by
that0n3guy
on Stack Overflow
See other posts from Stack Overflow
or by that0n3guy
Published on 2012-03-31T15:23:10Z
Indexed on
2012/03/31
17:29 UTC
Read the original article
Hit count: 401
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.
© Stack Overflow or respective owner