我有形成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谢谢你!我试过但没有运气。 –