You try to use character classes ([]
) wrong. The [^<\/div>]*
part means that number of characters except one of the following: <
,/
,d
,i
,v
,>
. This probably not what you meant.
What you could use is non-greedy repeat:
$regex = '/(<div\s*class=\"block_bc\"[^>]*>)(.+?)(<\/div>)/is';
Also, getting things out from html with regexp can be extremely brittle, try using the DOM for this with xpath. It's more verbose but also more resilient for badly formatted input:
$subject = '<div class="main"> <div class="block_bc"> <a href="index.php?x_param=11" class="BC-1"> Gallery</a> / <a href="path/Title_Item/?x_param=17" class="BC-2"> Title Item</a> / <span class="BC-3"> Bridge</span> </div> </div>';
libxml_use_internal_errors(true); // supress warnings
$doc = new DOMDocument;
$doc->loadHTML($subject);
$xpath = new DOMXpath($doc);
// get the <div class="main"> node for exporting
$main_node = $xpath->query('//div[@class="main"]');
// select the block_bc classed div's childs, and the textnodes under it
$childNodes = $xpath->query('//div[@class="block_bc"]/* | //div[@class="block_bc"]/text()');
foreach ($childNodes as $c) {
$c->parentNode->removeChild($c); // clear them all
}
// export the part of the document under the <div class="main">
print $doc->saveHTML($main_node->item(0));
// update:
// if you want the full document in html you can simply omit the parameter, with this you can get rid of the $main_node = ... line too
print $doc->saveHTML(); // this will print from doctype to </html>