dnotestine
asked on
PHP using preg_replace to remove form tags and everything in between
Using PHP I want to remove a form from a string that contains html - Here is the php code I have been trying to use but it doesn't work. Any ideas?
$html = "<form ... </form>"
$pattern = "/<form(.*?)<\/form>/i";
$html = preg_replace($pattern,"",$html);
(semicolon on the first line, btw - the one declaring $html)
ASKER
Thanks - the semicolon I forgot but was just for the comment here. The actual code in $html is:
<form action="http://www.artechchurchinteriors.com/portfolio/portfolio_zip_email.php" method='POST' name='hidden_email_form'>
<input type='text' id='email' name='email' value='enter email address to email list' size='35' onClick="SelectAll('email' );" />
<input type='hidden' name='hidden_html' id='hidden_html' value='' />
<input type='submit' name='submit' value=' Email Now ' />
</form>
-----------------
$html = preg_replace($pattern,"",$ html);
print "$html\n";
Does not take out the Form :-(
<form action="http://www.artechchurchinteriors.com/portfolio/portfolio_zip_email.php" method='POST' name='hidden_email_form'>
<input type='text' id='email' name='email' value='enter email address to email list' size='35' onClick="SelectAll('email'
<input type='hidden' name='hidden_html' id='hidden_html' value='' />
<input type='submit' name='submit' value=' Email Now ' />
</form>
-----------------
$html = preg_replace($pattern,"",$
print "$html\n";
Does not take out the Form :-(
ASKER
$pattern = "/<form(.*?)<\/form>/i";
$html = preg_replace($pattern,"",$ html);
$html = preg_replace($pattern,"",$
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
The "s" pattern modifier allows the . wildcard to match newlines
Note that the round brackets are unnecessary too...
$pattern = "/<form.*?<\/form>/is";
$pattern = "/<form.*?<\/form>/is";
Open in new window