额外的空间会减慢处理器的速度吗? [英] Does extra space slow down the processor?

查看:34
本文介绍了额外的空间会减慢处理器的速度吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

了解如何正确"取消设置节点后,我注意到使用 PHP 的 unset() 函数会留下制表符和空格.所以现在我有时在节点之间有一大块空白.我想知道 PHP 是否会遍历空格/返回/制表符,以及它是否最终会减慢系统速度.

After learning how to "correctly" unset a node, I noticed that using PHP's unset() function leaves the tabs and spaces behind. So now I have this big chunk of white space in between nodes at times. I'm wondering if PHP iterates through blank spaces/returns/tabs and whether it would eventually slow down the system.

我也想问有没有容易去除未设置留下的空间?

I'm also asking whether there's an easy to remove the space unset leaves behind?

谢谢,瑞恩

补充说明:

这就是我在取消设置节点后删除空格的方法,它对我有用.

This is how I removed the whitespaces after unsetting a node and it worked for me.

$dom = new DOMDocument();
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
$dom->load($xmlPath);
$dom->save($xmlPath);

推荐答案

它是否会减慢进程:可能很少关心.

Wether it slows down the process: probably to little to care about.

simpleXML 就是这么简单.如果你需要一个漂亮"的输出,DOM 是你的朋友:

And simpleXML is just that, simple. If you require a 'pretty' output, DOM is your friend:

<?php
$xml = '
<xml>
        <node>foo </node>
        <other>bar</other>
</xml>';
$x = new SimpleXMLElement($xml);
unset($x->other);
echo $x->asXML();

$dom = new DOMDocument();
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
$dom->loadXML($xml);
$dom->documentElement->removeChild($dom->documentElement->lastChild);
echo $dom->saveXML();

这篇关于额外的空间会减慢处理器的速度吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆