首页 \ 问答 \ 用于格式化PHP代码的Unix或VIM命令(Unix or VIM command to format PHP code)

用于格式化PHP代码的Unix或VIM命令(Unix or VIM command to format PHP code)

我知道你可以使用indent命令来美化c代码。 我想用php做同样的事情,但命令是给出错误(它只用于c我认为)是否有一种标准方法用命令格式化PHP代码? 我会接受OS X附带的unix命令或VIM命令。


I know that you can use the indent command to beautify c code. I want to do the same thing with php but the command is giving errors (it is intended for c only I believe) is there a standard way to formatt php code with a command? I would be open to either a unix command that comes with OS X or a VIM command.


原文:https://stackoverflow.com/questions/4233960
更新时间:2022-02-06 12:02

最满意答案

文本值由XLinq解释为XText。 因此您可以轻松检查节点是否为XText类型,或者通过检查NodeType来查看:

// get all text nodes
var textNodes = document.DescendantNodes()
                        .Where(x => x.NodeType == XmlNodeType.Text);

然而,这让我觉得你只想找到那些看起来有点孤独的文本命名为textvalue。 没有真正的方法来认识这种有效但不寻常的事情。 您可以检查父项是否被命名为“名称”,或者文本节点本身是单独还是不可见:

// get 'lost' textnodes
var lastTextNodes = document.DescendantNodes()
                            .Where(x => x.NodeType == XmlNodeType.Text)
                            .Where(x => x.Parent.Nodes().Count() > 1);

编辑一个额外的评论,我看到很多人声称这个XML是无效的。 我不同意这一点。 尽管它并不漂亮,但根据我的知识(和验证者)


Text values are interpreted by XLinq as XText. therefore you can easily check if a node is of type XText or by checking the NodeType see:

// get all text nodes
var textNodes = document.DescendantNodes()
                        .Where(x => x.NodeType == XmlNodeType.Text);

However, it strikes me that you only want to find that piece of text that seems a bit lonely named textvalue. There is no real way to recognize this valid but unusual thing. You can either check if the parent is named 'name' or if the textNode itself is alone or not see:

// get 'lost' textnodes
var lastTextNodes = document.DescendantNodes()
                            .Where(x => x.NodeType == XmlNodeType.Text)
                            .Where(x => x.Parent.Nodes().Count() > 1);

edit just one extra comment, i see that many people claim that this XML is invalid. I have to disagree with that. Although its not pretty, it's still valid according to my knowledge (and validators)

相关问答

更多

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。