文字クラス([]
)を間違って使用しようとしました。この部分は、次の[^<\/div>]*
いずれかを除く文字数を意味します:、、、、、、。これはおそらくあなたが意図したことではありません。<
/
d
i
v
>
使用できるのは、欲張りでない繰り返しです:
$regex = '/(<div\s*class=\"block_bc\"[^>]*>)(.+?)(<\/div>)/is';
また、正規表現を使用してhtmlから物事を取り出すことは非常に脆弱な場合があります。これには、xpathでDOMを使用してみてください。これはより冗長ですが、不適切な形式の入力に対してもより回復力があります。
$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>