Let me reprhase the question.
First, let's assume the HTML I am trying to match contains this:
<form action=/search name="other stuff" id="unnecessary">
or this:
<form id="unnecessary" action=/search name="other stuff">
(the id=, action=, name=, etc. can be in any order inside the <form> tag.)
Assume $HTML is a string of HTML containing multiple possible occurrences of the <form> tag.
Here's the code I'd like to work with:
$pattern = (some regular expression or series of regular expressions that would match <form [any text including id=, action=, name=, etc in any order]> but return the text directly in between 'action=' and a space.);
$replace = "<form action=".$_SERVER['PHP_SELF']."><input type=\"hidden\" name=\"original_url\" value=\"\$1\">";
$HTML = preg_replace($pattern, $replace, $HTML);
As you can see, the replacement (using the correct regular expression) would yield the line below if the above code was executed using my sample line of HTML where the form tag is. (The program will look for the string 'original_url' elsewhere to see if a form is being redirected to the proxy--'original_url' is not a variable/placeholder for something, so don't let it confuse you.)
<form action=/nameofthescript.php><input type="hidden" name="original_url" value="/search">
The entire original <form> tag would have to be replaced, and an <input> tag would be added after it.
That's what I'm trying to accomplish. What regular expression(s) would I have to use?