No. I was thinking about if something might sneak in between table and class. What you have still works fine as you can see here...
$content =
<<<EOS
<h3>First</h3>
<div>
<table class="gridView" cellspacing="0" cellpadding="2" rules="all" border="1" id="Test1" width="100%">table data</table>
</div>
<h3>Second</h3>
<div>
<table class="gridView" cellspacing="0" cellpadding="2" rules="all" border="1" id="Test2" width="100%">table data</table>
</div>
<h3>Third</h3>
<div>
<table class="gridView" cellspacing="0" cellpadding="2" rules="all" border="1" id="Test3" width="100%">table data</table>
</div>
EOS;
$content = preg_replace('#\<table class="gridView"(.+?)\<\/table\>#msi', '-', $content);
header('Content-type: text/plain');
echo $content;
You need to show what html code you actually have.
But do note that it's often less time consuming to write code that handles this through DOM instead of reg exp. At least once you get familiar with DOM and XPath.
However, there are a few things to note about PHP's DOM class. First off, if the document is using utf-8, DOM requires the presence of
<meta http-equiv="content-type" content="text/html; charset=utf-8">
even the documentation seems to imply that you can specify the characterset through the member methods (but I do believe they work for xml documents - but still not for xhtml).
You will also need a complete HTML document, but if you are not dealing with one, you simply prepend the html string with <html><head><title>a</title><meta http-equiv ...></head><body> and append </body></html>.
$content =
<<<EOS
<html>
<head>
<title>title</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>
<body>
<h3>First</h3>
<div>
<table class="gridView" cellspacing="0" cellpadding="2" rules="all" border="1" id="Test1" width="100%">
<tbody>
<tr><td></td></tr>
</tbody>
</table>
</div>
<h3>Second</h3>
<div>
<table class="gridView" cellspacing="0" cellpadding="2" rules="all" border="1" id="Test2" width="100%">
<tbody>
<tr><td>table data</td></tr>
</tbody>
</table>
</div>
<h3>Third</h3>
<div>
<table class="other" cellspacing="0" cellpadding="2" rules="all" border="1" id="Test3" width="100%">
<tbody>
<tr><td>åäö</td></tr>
</tbody>
</table>
</div>
</body>
</html>
EOS;
# Create a DOM document from your html source
$d = new DOMDocument();
$d->loadHTML($content);
# Create an XPath instance for this DOM document
$xp = new DOMXPath($d);
# Get all tables for which class="gridView"
$nl = $xp->query('//table[@class="gridView"]');
# The call to query returns a node list which you can iterate over in normal fashion
foreach ($nl as $n)
{
# These 2 lines is if you want to replce the tables with '
$t = $d->createTextNode('-');
$n->parentNode->insertBefore($t, $n);
# This is to remove each table node
$n->parentNode->removeChild($n);
}
header('Content-type: text/plain');
# If you want the entire document
# Note that there is also a member method called saveHTMLFile() to save directly to file
echo $d->saveHTML() . PHP_EOL . PHP_EOL;
# If you just want what's inside the body element
$bodies = $d->getElementsByTagName('body');
$html = trim($d->saveHTML($bodies->item(0)));
# <body> is 6 chars, </body> is 7 chars - strip those tags
$html = substr($html, 6, -7);
echo $html;