我一直在搜索信息,当我将 PHP 代码导出为 XML 时,如何删除它留下的标签值之间的空格,我将详细解释,首先我加载和 XML,然后我使用 xPath 对文件进行搜索,然后我删除了一些元素与某些品牌不匹配,最后我将其重新导出为新的 XML,问题是这个新的 XML 充满了代码留下的空格。我试过修剪它,但它似乎不能正常工作。
这是我的代码:
<?php
$sXML = simplexml_load_file('file.xml'); //First load the XML
$brands = $sXML->xPath('//brand'); //I do a search for the <brand> tag
function filter(string $input) { //Then I give it a list of variables
switch ($input) {
case 'BRAND 3':
case 'BRAND 4':
return false;
default:
return true;
}
}
array_walk($brands, function($brand) { //I remove all elements do not match my list
$content = (string) $brand;
if (filter($content)) {
$item = …Run Code Online (Sandbox Code Playgroud)