我有形成XML那樣的config.ini文件:正則表達式:如何刪除XML標籤風格
<positions>
<position>
<name>BLOCK TAB 1</name>
<tag>[BLOCK_TAB_1]</tag>
</position>
<position>
<name>PERSONALAREA</name>
<tag>[PERSONALAREA]</tag>
</position>
</positions>
我試圖刪除塊:使用的preg_replace
<position>
<name>BLOCK TAB 1</name>
<tag>[BLOCK_TAB_1]</tag>
</position>
$find1 = "/<name>BLOCK TAB 1<\/name>/";
$find2 = "/<tag>\[BLOCK_TAB_1\]<\/tag>/";
$contents = preg_replace($find1, "", $contents);
$contents = preg_replace($find2, "", $contents);
但內容將是
<positions>
<position>
</position>
<position>
<name>PERSONALAREA</name>
<tag>[PERSONALAREA]</tag>
</position>
</positions>
空的<position>
標籤(內部有標籤)仍然在這裏。
儘量使用/<position[^>]*><\\/position[^>]*>/
來代替空的<position>
標籤,但由於標籤內,因此替換不起作用。
有人有想法嗎?
「」 \ n \ S + BLOCK TAB 1 \ n \ S + \ [BLOCK_TAB_1 \] \ n \ S + 「 '使用這個或'」 \ n \ S + 。* \ n \ S + 。* \ n \ S + 「' –
Ashish
@Ashish謝謝你!我試過但沒有運氣。 –