次のようなファイルがあります。
<div clas='dsfdsf'> this is first div </div>
<div clas='dsfdsf'> this is second div </div>
<div class="remove">
<table>
<thead>
<tr>
<th colspan="2">Mehr zum Thema</th>
</tr>
</thead>
<tbody>
<tr> this is tr</tr>
<tr> this row no 2 </tr>
</tbody>
</table>
</div>
<div clas='sasas'> this is last div </div>
このファイルの内容を次のような変数で取得しました。
$Cont = file_get_contents('myfile');
preg_replace で div をクラス名「remove」に置き換えたいと思います。私はこれを試しました:
$patterns = "%<div class='remove'>(.+?)</div>%";
$strPageSource = preg_replace($patterns, '', $Cont);
それは動かなかった。この置換の正しい正規表現は何ですか?