关于取一段字符串中的一段xml的问题?
橱窗的光
橱窗的光 2017-03-06 09:48:12
0
2
989
Blockly.Blocks['kjh'] = { init: function() { this.appendDummyInput().appendField('kjh'); this.setOutput(true, null); this.setColour(164); this.setTooltip(''); this.setHelpUrl(''); } }; Blockly.JavaScript['kjh'] = function(block) { var code = 'gdfnh'; return [code, Blockly.JavaScript.ORDER_NONE]; }   

请问如何取这段字符串中的xml部分?非常感谢!

橱窗的光
橱窗的光

reply all (2)
数据分析师

Regarding the problem of taking a piece of xml from a string? -PHP Chinese website Q&A-About the problem of fetching a piece of xml from a string? -PHP Chinese website Q&A

Let’s take a look and learn.

    迷茫

    遇到这种我的一般做法是利用replace+正则来提取。

    var t = `Blockly.Blocks['kjh'] = { init: function() { this.appendDummyInput().appendField('kjh'); this.setOutput(true, null); this.setColour(164); this.setTooltip(''); this.setHelpUrl(''); } }; Blockly.JavaScript['kjh'] = function(block) { var code = 'gdfnh'; return [code, Blockly.JavaScript.ORDER_NONE]; }   `; var res; t.replace(/]+>[\s\S]*?<\/xml>/,function(e){ res = e; return e });

    这里主要一个正则是关于这段文本如果有回车换行的情况,直接用.*并不能直接匹配,但可用[\s\S]*代替

      Latest Downloads
      More>
      Web Effects
      Website Source Code
      Website Materials
      Front End Template
      About us Disclaimer Sitemap
      php.cn:Public welfare online PHP training,Help PHP learners grow quickly!