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);

Open in new window

dnotestineAsked:
Who is Participating?
 
Terry WoodsIT GuruCommented:
This should do it:

$pattern = "/<form(.*?)<\/form>/is";
$html = preg_replace($pattern,"",$html);
0
 
codefluxCommented:
You're missing a semicolon.

<?php
$html = "before <form blah blah blah </form> after";
$pattern = "/<form(.*?)<\/form>/i";
$html = preg_replace($pattern,"",$html);
print "$html\n";
?>

Open in new window

0
 
codefluxCommented:
(semicolon on the first line, btw - the one declaring $html)
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
dnotestineAuthor Commented:
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');" />&nbsp;&nbsp;
<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 :-(
0
 
dnotestineAuthor Commented:
$pattern = "/<form(.*?)<\/form>/i";
$html = preg_replace($pattern,"",$html);
0
 
Terry WoodsIT GuruCommented:
The "s" pattern modifier allows the . wildcard to match newlines
0
 
Terry WoodsIT GuruCommented:
Note that the round brackets are unnecessary too...

$pattern = "/<form.*?<\/form>/is";
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.